Apple® He Technical Reference Second Edition Preface Chapters 1 through 7 * APPLE COMPUTER, INC. This manual is copyrighted by APDA, Profile, and UniDisk Apple or bv Apple's suppliers, are trademarks of with all rights reserved. Under Apple Computer, Inc. the copyright laws, this manual may not be copied, in whole or ITC Zapf Dingbats is a in part, without the written registered trademark of consent of Apple Computer, International Typeface Inc. This exception does not Corporation. allow copies to be made for Linotronic is a registered others, whether or not sold, but trademark of Linotype Co. all of the material purchased may be sold, given, or lent to Varityper is a registered another person. Under the law, trademark, and VT600 is a copying includes translating trademark, of AM International, into another language. Inc. The Apple logo is a registered POSTSCRIPT is a registered trademark ofAppIe Computer, trademark, and Illustrator is a Inc. Use of the "keyboard" trademark, of Adobe Systems Apple logo (Option-Shift-K) for Incorporated. commercial purposes without the prior written consent of Simultaneously published in the Apple may constitute United States and Canada. trademark infringement and unfair competition in violation of federal and state laws. © Apple Computer, Inc., 1989 20525 Mariani Avenue Cupertino, CA 95014-6299 (408) 996-1010 Apple, the Apple logo, Apple JIGS, AppleTalk, ImageWriter, LaserWriter, Macintosh, and ProDOS are registered trademarks of Apple Computer, Inc. Contents Figures and tables / xix Preface / xxix Contents of this manual / xxx Conventions used in this manual / xxxii Typographic conventions / xxxii Notation and terminology conventions / xxxiii How to get more information / xxxiii APDA / xxxiv User groups / xxxiv Apple Developer Services / xxxv Introduction: The Apple He Family / 1 Software identification of an Apple lie / 2 Versions of the Apple He ROM / 3 The original Apple He / 4 The outside of the original Apple He / 5 The keyboard / 7 Operating features / 9 Cursor movement keys / 9 Modifier keys / 9 Special function keys / 10 Front panel switches / 10 Disk-use and power lights / 14 The volume control and audio output jack / 14 The door for the internal disk drive / 15 The back panel / 16 The external power supply / 19 iii The inside of the original Apple He / 19 The internal voltage converter / 20 The main logic board / 20 The other circuit boards / 22 The UniDisk 3.5 Apple He / 23 The outside of the UniDisk 3.5 Apple He / 23 The inside of the UniDisk 3.5 Apple lie / 24 The memory expansion Apple He / 24 The outside of the memory expansion Apple He / 25 The inside of the memory expansion Apple He / 25 The Apple He Plus / 26 The outside of the Apple He Plus / 27 The keyboard / 29 Operating features / 31 Special function keys / 31 Front panel switches / 31 Disk-use and power lights / 34 The speaker / 35 The disk-access opening for the internal disk drive / 35 The back panel / 36 The inside of the Apple lie Plus / 37 The internal power supply / 38 The main logic board / 39 The other circuit boards / 40 Using the accelerator feature / 41 The 65C02 microprocessor / 41 Address Map and Memory / 45 Overview of the address space / 46 Address map / 47 Main RAM addresses ($0000-$BFFF and $D000-$FFFF) / 50 Auxiliary RAM addresses ($0000-$BFFF and $D0O0-$FFFF) / 50 ROM addresses ($C100-$FFFF) / 50 Hardware addresses ($C0OO-$C0FF) / 52 Bank-switched memory / 53 Apple lie Technical Reference Page allocations / 53 Page $00 (one-byte addresses) / 53 Page $01 (the 65C02 stack) / 54 Pages $D0-$FF (ROM and RAM) / 54 Using bank-switched-memory selector switches / 54 48K address space / 63 Page allocations / 64 Page $02 (the input buffer) / 64 Page $03 (global storage and vectors) / 64 Pages $04-$07 (text and Lo-Res graphics Page 1) / 64 Pages $08-$0B (text and Lo-Res graphics Page 2) / 66 Page $08 (communication port buffers) / 66 Pages $20-$3F (Hi-Res graphics Page 1) / 67 Pages $40-$5F (Hi-Res graphics Page 2) / 67 Using 48K address space switches / 67 Transfers between main and auxiliary memory / 69 Transferring data / 70 Transferring control / 71 Using display memory switches / 72 Resets and Interrupts / 77 Starts and resets / 78 The initial stale of the machine / 80 The reset vector / 82 The cold-start procedure / 83 Original Apple He / 84 UniDisk 3-5 Apple He / 85 Memory expansion Apple He / 85 Apple He Plus / 86 Forced cold reset / 87 The warm-start procedure / 88 Interrupts / 89 Introduction / 89 Interrupt handling on the 65C02 / 90 The interrupt vector at $FFFE / 91 The built-in interrupt handler / 91 Saving the memory configuration / 93 Managing main and auxiliary stacks / 93 Contents User's interrupt handler at $03FE / 94 Handling break instructions / 95 Sources of interrupts / 96 Firmware handling of interrupts / 97 Firmware for mouse and VBL interrupts / 97 Firmware for keyboard interrupts / 98 Using keyboard buffering firmware / 99 Using keyboard interrupts through firmware / 100 Using external interrupts through firmware / 100 Firmware for serial interrupts / 101 Using serial buffering transparently / 102 Using serial interrupts through firmware / 103 Transmitting serial data / 103 A loophole in the firmware / 104 Bypassing the interrupt firmware / 104 Using mouse interrupts without the firmware / 105 Using ACIA interrupts without the firmware / 106 Introduction to Apple He I/O / 107 The standard I/O links / 108 Standard input routines / 110 RdKey subroutine / 1 1 1 GetLn subroutine / 1 1 1 Escape sequences with GetLn / 112 Editing with GetLn / 114 Cancel line / 114 Backspace / 114 Retype / 115 The Keyln and C3KeyIn input routines / 115 Standard output routines / 115 COut subroutine / 116 Control characters with COutl / 116 Control characters with C3COutl / 117 The stop-list feature / 119 The text window / 119 Normal, inverse, and flashing text / 120 Primary-character-set display / 121 Alternate-character-set display / 122 vi Apple He Technical Reference Port I/O / 122 Standard port entry points / 123 Firmware protocol / 124 Port I/O space / 126 Port ROM space / 126 Expansion ROM space / 127 Port screen hole RAM space / 127 Interrupts / 128 Keyboard and Speaker / 129 Keyboard input / 130 Reading the keyboard / 130 Monitor firmware support for keyboard input / 134 GetLnZ / 134 GetLnl / 134 RdChar / 134 Speaker output / 135 Using the speaker / 135 Monitor firmware support for speaker output / 136 Belli / 136 Bell / 136 Video Output / 137 Video display specifications / 139 Enhanced video firmware / 140 Text modes / 143 Text character sets / 143 MouseText / 144 40-column versus 80-column text / 146 Graphics modes / 147 Lo-Res graphics / 147 Hi-Res graphics / 149 Double Hi-Res graphics / 152 Mixed-mode displays / 154 Display pages / 155 Display mode switching / 156 Display page maps / 160 Contents Monitor support for video display output / 167 I/O firmware support for video output / 168 PInit / 168 PRead / 169 PWrite / 169 PStatus / 170 7 Serial Port I/O / 171 Sending commands to the serial ports / 172 Using serial port 1 / 172 Using serial port 2 / 174 Serial port command set / 175 Port 1 / 179 Characteristics of port 1 at startup / 179 Hardware page locations for port 1 / 180 I/O firmware support for port 1 / 180 Screen hole locations for port 1 / 1 8 1 Changing port 1 characteristics / 182 Data format and communication rate / 183 Carriage return and line feed / 185 Sending special characters / 185 Displaying output on the screen / 186 Port 2 / 186 Characteristics of port 2 at startup / 187 Hardware page locations for port 2 / 1 8 7 I/O firmware support for port 2 / 1 8 8 Screen hole locations for port 2 / 1 8 9 Changing port 2 characteristics / 190 Data format and transmission rate / 191 Carriage return and line feed / 193 Routing input and output / 193 Half-duplex operation / 194 Full-duplex operation / 196 Terminal mode / 199 vffl Apple lie Technical Reference 8 Block Device I/O / 201 Disk drive I/O / 202 Original Apple He / 202 UniDisk 3.5 and memory expansion Apple lie / 203 Apple lie Plus / 204 Memory expansion card I/O / 205 Using SmartPort / 207 Locating SmartPort / 207 Issuing a call to SmartPort / 208 SmartPort assignment of unit numbers / 210 External disk drive options / 211 Reading the SmartPort call descriptions / 212 Generic SmartPort calls / 214 Status ($00) / 215 ReadBlock ($01) / 221 WriteBlock ($02) / 223 Format ($03) / 225 Control ($04) / 227 Init ($05) / 230 Open ($06) / 231 Close ($07) / 232 Read ($08) / 233 Write ($09) / 235 Device-specific SmartPort calls / 237 SmartPort calls specific to the Apple 3.5 disk drive / 237 Eject / 238 Control code / 238 Control list / 238 SmartPort calls specific to UniDisk 3.5 / 238 Eject / 239 Control code / 239 Control list / 239 Execute / 239 Control code / 240 Control list / 240 SetAddress / 240 Control code / 240 Control list / 241 Contents ix Download / 241 Control code / 241 Control list / 241 UniDiskStat / 241 Status code / 242 Status list / 242 An example of a SmartPort call in a program / 242 Summary of commands and parameters / 247 Summary of SmartPort error codes / 248 9 Mouse and Game Input / 251 Mouse input / 252 Mouse connector signals / 253 Mouse operating modes / 253 Transparent mode / 254 Movement interrupt mode / 254 Button interrupt mode / 255 Movement/button interrupt mode / 255 Vertical-blanking-active modes / 255 Mouse soft switches and status bits / 255 I/O firmware support for mouse input / 257 Pascal support / 260 BASIC and assembly-language support / 26l Screen holes / 261 Using the mouse as a hand control / 263 Game input / 263 The hand control connector signals / 264 Switch inputs (SwO and Swl) / 265 Analog inputs (PdlO and Pdll) / 265 Monitor support for game input / 266 10 Using the Monitor / 267 Invoking the Monitor / 268 Syntax of Monitor commands / 269 Monitor memory commands / 270 Examining memory contents / 270 Memory dump / 271 Apple lie Technical Reference Changing memory contents / 273 Changing one byte / 273 Changing consecutive locations / 274 Moving data in memory / 275 Comparing data in memory / 276 Monitor register commands / 277 Changing registers / 277 Examining registers / 278 Miscellaneous Monitor commands / 278 Display inverse and normal / 279 Back to BASIC / 279 Redirecting input and output / 280 Hexadecimal arithmetic / 280 Advanced operations / 281 Multiple-command lines / 281 Filling memory / 282 Repeating commands / 283 Creating your own commands / 284 Machine-language programs / 284 Running a program / 285 Disassembled programs / 285 The Step and Trace commands / 287 The mini-assembler / 289 Starting the mini-assembler / 290 Using the mini-assembler / 290 Mini-assembler instruction formats / 292 Summary of Monitor commands / 294 11 Hardware / 297 Environmental specifications / 298 Block diagrams / 299 Power supplies / 304 The Apple lie power supply / 304 The Apple He external transformer / 304 The external power connector / 305 The Apple He internal voltage converter / 306 The Apple lie internal power connector / 307 The Apple He Plus internal power supply / 310 Contents xi The 65C02 microprocessor / 312 65C02 block diagram / 312 65C02 timing / 314 The custom integrated circuits / 317 The memory management unit (MMU) / 318 The input/output unit (IOU) / 320 The timing generator (TMG) / 323 The general logic unit (GLU) / 324 The disk controller unit (IWM) / 325 The Apple lie Plus multidrive interface glue (M1G) / 327 The Apple He Plus cache glue gate array (CGGA) / 329 Enabling and disabling the accelerator / 333 The ROM Wait routine / 334 Memory addressing / 334 ROM addressing / 335 RAM addressing / 339 Dynamic RAM refreshment / 340 Dynamic RAM timing / 343 The Apple lie Plus MIG RAM / 345 The Apple He Plus accelerator cache RAM / 347 The keyboard / 350 The speaker / 356 Volume control / 358 Audio output jack / 358 The video display / 358 The video counters / 359 Display memory addressing / 360 Display address mapping / 360 Video display modes / 365 Text displays / 367 Lo-Res display / 369 Hi-Res display / 371 Double Hi-Res display / 372 Video output signals / 373 Monitor output / 373 Video expansion output / 374 Disk I/O / 377 xii Apple lie Technical Reference Serial 1/0 / 382 ACIA control register / 388 ACIA command register / 389 ACIA status register / 389 ACIA transmit/receive register / 391 Mouse input / 391 Hand control input / 397 Memory expansion card / 402 Apple lie Plus internal modem connector / 405 Schematic diagrams / 406 A The 65C02 Microprocessor / 419 Differences between 6502 and 65C02 / 420 Differing cycle times / 420 Differing instruction results / 421 Data sheet / 422 B Address Map / 433 Page $00 / 434 Page $03 / 439 Screen holes / 440 The hardware page (SCO) / 444 C Operating Systems and Languages / 451 Operating systems / 452 ProDOS / 452 DOS / 452 Pascal Operating System / 452 Languages / 453 Applesoft BASIC / 453 Integer BASIC / 453 Pascal language / 453 Fortran / 454 Logo II / 454 r Contents xiii D Apple D-Family Differences / 455 Overview / 456 Type of processor / 458 Machine identification / 458 Memory structure / 459 Amount and address ranges of RAM / 459 Amount and address ranges of ROM / 460 Peripheral-card memory spaces / 461 Hardware addresses / 461 $C000-$C00F / 461 SC010-SC01F / 462 $C020-$C02F / 462 $C030-$C03F / 462 $C040-$C04F / 462 $C050-$CO5F / 463 $C060-$C06F / 463 $C070-$C07F / 464 $C080-$C08F / 464 $C090-$C0FF / 464 System Monitor / 464 I/O in general / 465 DMA transfers / 465 Slots versus ports / 465 Interrupts / 466 The keyboard / 466 Keys, switches, and lights / 466 Character sets / 467 The speaker / 467 The video display / 468 Character sets / 468 MouseText / 468 Vertical blanking / 469 Display modes / 469 Disk I/O / 469 Serial I/O / 470 Serial ports versus serial cards / 470 Serial I/O buffers / 471 xiv Apple He Technical Reference Mouse and hand controls / 471 Mouse input / 472 Hand control input and output / 474 Cassette I/O / 475 Hardware / 475 Power / 475 Custom chips / 476 E USA and International Models / 477 Keyboard layouts and codes / 478 USA standard (QWERTY) keyboard / 479 USA simplified (Dvorak) keyboard / 481 ISO layout of USA keyboard / 482 British keyboard / 482 French keyboard / 483 Canadian keyboard / 485 German keyboard / 487 Italian keyboard / 488 Western Spanish keyboard / 490 ASCII character sets / 492 Power supply specifications / 494 F Firmware Entry Points / 495 SF800 Plot / 500 SF80E Ploll / 501 $F819 HLine / 502 $F828 VLine / 503 SF832 ClrScr / 504 $F836 ClrTop / 505 $F847 GBasCalc / 506 $F85F NxtCol / 507 $F864 SetCol / 508 $F871 Scrn / 510 $F88C InsDsl.2 / 511 $F88E InsDs2 / 512 SF8D0 InstDsp / 513 Contents xv SF940 PrnlYX / 514 $F941 PrntAX / 515 $F944 PrnlX / 516 SF948 PrBInk / 517 $F94A PrBI2 / 518 SF953 PCAdj / 519 SFA40 OldlRQ / 520 SFA47 NewBrk / 521 SFA4C Break / 522 SFA59 OldBrk / 523 SFA62 Reset / 524 SFAA6 PwrUp / 525 $FAD7 RegDsp / 526 $FB1E PRead / 527 $FB21 PRead4 / 528 $FB2F Init / 529 SFB39 SetTxt / 530 SFB40 SetGr / 531 $FB4B SetWnd / 532 $FB5B TabV / 533 $FB60 Applell / 534 SFB6F SetPwrC / 535 SFB78 VidWait / 536 SFB88 KbdWait / 537 $FBB3 Version / 538 SFBBF ZIDByte2 / 539 SFBCO ZIDByte / 540 SFBC1 BasCalc / 541 SFBDD Belli / 542 SFBE2 Belli.2 / 543 $FBE4 Bell2 / 544 SFBFO StorAdv / 545 $FBF4 Advance / 546 SFBFD VidOut / 547 $FC10 BS / 548 SFC1A Up / 549 SFC22 VTab / 550 xvi Apple He Technical Reference $FC24 VTabz / 551 $FC42 CIrEOP / 552 $FC58 Home / 553 $FC62 CR / 554 SFC66 LF / 555 $FC70 Scroll / 556 SFC9C CIrEOL / 557 $FC9E ClrEOLZ / 558 $FCA8 Wait / 559 $FCB4 NxtA4 / 561 $FCBA NxtAl / 562 $FCC9 IleadR / 563 SFDOC RdKey / 564 $FD10 FD10 / 565 $FD18 KeylnO / 566 $FD1B Keyln / 567 $FD35 RdChar / 569 $FD67 GelLnZ / 571 $FD6A GetLn / 572 $FD6C GetLnO / 574 $FD6F GetLn 1 / 575 $FD8B CROutl / 576 SFD8E CROut / 577 SFD92 PrAl / 578 SFDDA PrByte / 579 $FDE3 PrHex / 580 $FDED COul / 581 $FDF0 COutl / 582 $FDF6 COutZ / 583 $FE1F IDRoutine / 584 $FE2C Move / 585 $FE36 Verify / 586 $FE5E List / 587 $FE80 Setlnv / 588 $FE84 SelNorm / 589 $FE89 SetKbd / 590 $FE8B InPort / 591 Contents xvii $FE93 SelVid / 592 SFE95 OutPort / 593 $FEB6 Go / 594 SFECD Write / 595 $FEFD Read / 596 $FF2D PrErr / 597 $FF3A Bell / 598 $FF3F Restore / 599 $FF4A Save / 600 $FF58 IORTS / 601 $FF59 OldRst / 602 $FF65 Mon / 603 $FF69 MonZ / 604 $FF70 MonZ4 / 605 $FF8A Dig / 606 $FFA7 GctNum / 607 SFFAD NxlChr / 608 SFFC7 ZMode / 609 G Conversion Tables / 611 Bits and bytes / 612 Hexadecimal and decimal / 614 Hexadecimal and negative decimal / 615 Peripheral identification numbers / 617 Apple lie-family character set / 619 H Controlling the Apple He Plus Accelerator / 625 CGGA commands / 627 $01 Enable Accelerator / 629 $02 Disable Accelerator / 629 $03 Lock Accelerator / 630 $04 Unlock Accelerator / 630 $05 Read Accelerator / 631 $06 Write Accelerator / 633 Code sample / 634 Glossary / 641 Index / 667 xviil Apple lie Technical Reference Figures and tables Introduction: The Apple He Family / 1 Figure 1-1 Original Apple He external features, front / 6 Figure 1-2 Original Apple He external features, back / 7 Figure 1-3 Front of original Apple He with standard USA keyboard / 8 Figure 1-4 Key assignments for original Apple He keyboard, with keyboard switch up (standard Sholes position) / 12 Figure 1-5 Key assignments for original Apple He keyboard, with keyboard switch down (Dvorak position) / 13 Figure 1-6 Apple lie volume control and audio output jack / 15 Figure 1-7 Internal disk drive door / 16 Figure 1-8 Original Apple He back panel connectors / 18 Figure 1-9 Power supply and voltage converter / 19 Figure 1-10 Inside the original Apple He / 20 Figure 1-11 Original Apple He main logic board / 22 Figure 1-12 Memory expansion Apple lie main logic board / 26 Figure 1-13 Apple lie Plus external features, front / 28 Figure 1-14 Apple lie Plus external features, back / 28 Figure 1-15 Front of the Apple He Plus with Apple Standard Keyboard layout / 30 Figure 1-16 Key assignments for the Apple He Plus keyboard, with keyboard switch up (standard Sholes position) / 33 Figure 1-17 Key assignments for the Apple He Plus keyboard, with keyboard switch down (Dvorak position) / 34 Figure 1-18 Apple He Plus internal disk drive door / 35 Figure 1-19 Apple He Plus back panel connectors / 37 Figure 1-20 Inside the Apple lie Plus / 38 Figure 1-21 Apple lie Plus main logic board / 40 Figure 1-22 Internal model of the 65C02 microprocessor / 43 Table 1-1 Apple He-family identification bytes / 3 Table 1-2 Original Apple He keyboard specifications / 9 Table 1-3 Apple lie Plus keyboard specifications / 31 Figure and tables xlx 2 Address Map and Memory / 45 Figure 2-1 Apple He family address map / 49 Figure 2-2 Read ROM / 57 Figure 2-3 Read ROM, write RAM, and use $D0OO Bank 1 / 58 Figure 2-4 Read ROM, write RAM, and use $D00O Bank 2 / 5 9 Figure 2-5 Read RAM and use $DOO0 Bank 1 / 60 Figure 2-6 Read RAM and use $DOO0 Bank 2 / 6 1 Figure 2-7 Read and write RAM and use $D0OO Bank 1 / 62 Figure 2-8 Read and write RAM and use SDOOO Bank 2 / 6 3 Figure 2-9 48K address map / 65 Figure 2-10 48K address selection, split pairs / 68 Figure 2-11 48K address selection, one side only / 69 Figure 2-12 Page2 selections, 80Slore on and HiRes off / 74 Figure 2-13 Page2 selections, 80Store on and HiRes on / 75 Table 2-1 Bank-switched memory selector switches / 56 Table 2-2 48K address-space switches / 68 Table 2-3 48K address space transfer routines / 70 Table 2-4 Parameters for MoveAux routine / 71 Table 2-5 Parameters for XFer routine / 72 Table 2-6 Display memory switches / 73 3 Resets and Interrupts / 77 Figure 3-1 Reset routine flowchart / 79 Table 3-1 Page $03 vectors / 80 Table 3-2 Inlerrupt-handling sequence / 92 Table 3-3 Break handler state-saving format / 95 Table 3-4 Encoded memory slate definition / 95 Table 3-5 Activating mouse interrupts / 105 Table 3-6 Reading mouse interrupts / 105 4 Introduction to Apple He I/O / 107 Table 4-1 Prompt characters / 112 Table 4-2 Escape sequences with GetLn / 113 Table 4-3 Control characters with COutl / 117 Table 4-4 Control characters with C3COutl / 118 Table 4-5 Text window memory locations / 120 Table 4-6 Original and UniDisk 3.5 Apple lie port characteristics / 123 xx Apple He Technical Reference Table 4-7 Memory expansion Apple He and Apple lie Plus port characteristics / 124 Table 4-8 Firmware protocol locations / 125 Table 4-9 Port I/O locations / 126 Table 4-10 Port screen hole memory locations / 127 5 Keyboard and Speaker / 129 Table 5-1 Keyboard input characteristics / 131 Table 5-2 Keys and ASCII codes / 132 Table 5-3 Speaker output characteristics / 135 6 Video Output / 137 Figure 6-1 Text modes and how to switch between them / 142 Figure 6-2 MouseText characters / 145 Figure 6-3 40-column and 80-column text with alternate character set / 146 Figure 6-4 Hi-Res display bits / 150 Figure 6-5 Map of 40-column text display / 162 Figure 6-6 Map of 80-column text display / 163 Figure 6-7 Map of Lo-Res graphics display / 164 Figure 6-8 Map of Hi-Res graphics display / 165 Figure 6-9 Map of Double Hi-Res graphics display / 166 Table 6-1 Video output port (port 3) characteristics / 139 Table 6-2 Video display specifications / 139 Table 6-3 Comparison of standard and enhanced video firmware / 141 Table 6-4 Display character sets / 144 Table 6-5 Lo-Res graphics colors / 148 Table 6-6 Hi-Res graphics colors / 151 Table 6-7 Double Hi-Res graphics colors / 153 Table 6-8 Video display page locations / 156 Table 6-9 Display soft switches / 157 Table 6-10 Display modes supported by firmware, including Applesoft / 158 Table 6-11 Other display modes / 159 Table 6-12 Monitor Firmware routines / 167 Table 6-13 Port 3 firmware protocol table / 168 Table 6-14 Video control functions / 170 Figure and tables xxl 7 Serial Port I/O / 171 Figure 7-1 Diagram of port 1 characteristics storage port 1 / 183 Figure 7-2 Data format / 184 Figure 7-3 Diagram of port 2 characteristics storage / 191 Figure 7-4 Devices in a typical communication setup communication / 192 Figure 7-5 Effect of IN#2 / 194 Figure 7-6 Effect of IN#2 and T command, half duplex / 195 Figure 7-7 Effect of IN#2 and T command, full-duplex terminal / 196 Figure 7-8 Effect of IN#2, PR#2, and T command, full-duplex host / 198 Table 7-1 Serial port commands / 176 Table 7-2 Serial port 1 characteristics / 179 Table 7-3 Port 1 hardware page locations / 180 Table 1A Port 1 I/O firmware protocol / 181 Table 7-5 Port 1 screen hole locations / 181 Table 7-6 Serial port 2 characteristics / 186 Table 7-7 Port 2 hardware page locations / 188 Table 7-8 Port 2 I/O firmware protocol / 188 Table 7-9 Port 2 screen hole locations / 189 8 Block Device I/O / 201 Table 8-1 Disk port characteristics of the original Apple lie / 202 Table 8-2 Disk port characteristics of the UniDisk 35 and memory expansion Apple lie / 203 Table 8-3 Disk port characteristics of the Apple He Plus / 204 Table 8-4 Memory expansion card port characteristics / 206 Table 8-5 SmartPort ID Type byte / 208 Table H Contenls of the 65C02 registers after a SmartPort call / 210 Table 8-7 Summary of standard commands and parameter lists / 247 9 Mouse and Game Input / 251 Table 9-1 Mouse input port characteristics / 252 Table 9-2 Mouse soft switches and status bits / 256 Table 9-3 Offsets for pointers to Mouse firmware routines / 259 Table 9-4 Mouse port I/O firmware protocol for Pascal / 260 Table 9-5 Mouse port screen hole locations / 262 Table 9-6 Game input characteristics / 264 xxii Apple He Technical Reference 10 Using the Monitor / 267 Table 10-1 Mini-assembler address formats / 293 11 Hardware / 297 Figure 1 1-1 Apple lie block diagram / 301 Figure 11-2 Apple lie Plus block diagram / 303 Figure 11-3 Apple lie external power connector / 306 Figure 1 1-4 Apple lie internal power connector / 308 Figure 1 1-5 Apple lie Plus internal power connector / 311 Figure 11-6 65C02 block diagram/ 313 Figure 1 1-7 System timing signals / 316 Figure 11-8 MMU pinouts / 319 Figure 11-9 IOU pinouts / 321 Figure 11-10 TMG pinouts / 323 Figure 1 1-11 GLU pinouts / 324 Figure 11-12 IWM pinouts / 326 Figure 11-13 MIG chip pinouts / 327 Figure 11-14 Apple lie Plus accelerator chip pinouts / 330 Figure 11-15 Memory bus organization / 335 Figure 11-16 23256 ROM pinouts / 336 Figure 11-17 2316 ROM pinouts / 337 Figure 11-18 2361 ROM pinouts / 338 Figure 11-19 64 Kbit RAM pinouts / 341 Figure 11-20 Pinouts of 256 Kbit RAM chip / 342 Figure 11-21 RAM timing signals / 345 Figure 11-22 MIG RAM pinouts / 346 Figure 1 1-23 Accelerator cache RAM pinouts / 347 Figure 11-24 Keyboard circuit block diagram / 351 Figure 11-25 Keyboard connector / 352 Figure 11-26 Keyboard signals / 355 Figure 11-27 Speaker circuit diagram / 357 Figure 11-28 Display address transformation / 36l Figure 11-29 40-column text display memory / 364 Figure 1 1-30 Video display circuits / 366 Figure 11-31 7 MHz video timing signals: 40-column, Lo-Res, and Hi-Res display / 368 Figure 11-32 14 MHz video timing signals: 80-column and Double Hi-Res display / 369 Figure 11-33 Video output back panel connectors / 374 Figure 11-34 Video expansion connector pinouts / 376 Figure and tables xxiii Figure 11-35 External disk drive connector / 378 Figure 11-36 Internal disk drive connector for the Apple lie and Apple lie Plus / 380 Figure 11-37 Serial port circuits / 383 Figure 11-38 6551 ACIA block diagram / 384 Figure 11-39 ACIA pinouts / 385 Figure 11-40 Apple He serial port connectors / 386 Figure 11-41 Apple lie Plus serial port connectors / 387 Figure 11-42 ACIA control register / 388 Figure 11-43 ACIA command register / 389 Figure 11-44 ACIA status register / 390 Figure 11-45 Sample mouse waveform / 392 Figure 11-46 Mouse movement and direction waveforms / 393 Figure 11-47 Mouse connector / 394 Figure 11-48 Mouse circuits / 395 Figure 11-49 Mouse button signals / 396 Figure 11-50 Hand control connector / 397 Figure 11-51 How to connect switch inputs / 399 Figure 11-52 Hand control circuits / 400 Figure 11-53 Hand control signals / 401 Figure 11-54 Memory expansion card connector pinouts / 403 Figure 11-55 Apple He Plus expansion connector / 405 Figure 11-56 Apple lie Plus internal modem connector / 406 Figure 11-57 Schematic diagrams for the Apple He / 407 Figure 11-58 Schematic diagrams for the Apple He Plus / 412 Table 11-1 Environmental specifications / 298 Table 11-2 Apple lie power transformer specifications / 305 Table 11-3 Apple He external power connector signals / 306 Table 11-4 Apple lie internal voltage converter specifications / 307 Table 11-5 Apple He internal power connector signals / 309 Table 11-6 Apple He Plus internal power supply specifications / 310 Table 11-7 Apple He Plus internal power connector signals / 311 Table 11-8 65C02 microprocessor specifications / 314 Table 11-9 System timing signal descriptions / 317 Table 11-10 MMU signal descriptions / 319 Table 11-11 IOU signal descriptions / 321 Table 11-12 TMG signal descriptions / 323 Table 11-13 GLU signal descriptions / 324 Table 11-14 IWM signal descriptions / 326 Table 11-15 MIG chip signal descriptions / 328 xxiv Apple He Technical Reference Table 11-16 Apple He Plus accelerator chip signal descriptions / 331 Table 11-17 23256 ROM signal descriptions / 336 Table 11-18 2316 ROM signal descriptions / 337 Table 11-19 2364 ROM signal descriptions / 339 Table 11-20 64 Kbit RAM signal descriptions / 341 Table 11-21 256 Kbit RAM signal descriptions / 342 Table 11-22 RAM address multiplexing / 343 Table 11-22 RAM address multiplexing / 343 Table 11-23 RAM timing signals / 344 Table 11-24 MIG RAM signal descriptions / 346 Table 11-25 Cache data RAM signal descriptions / 348 Table 11-26 Cache tag RAM signal descriptions / 349 Table 11-27 Apple lie keyboard connector signals / 353 Table 11-28 Apple lie Plus keyboard connector signals / 354 Table 11-29 Display memory addressing / 362 Table 11-30 Memory address bits for display modes / 363 Table 11-31 Character-generator control signals / 370 Table 11-32 Video expansion connector signals / 376 Table 11-33 External disk drive connector signals for the Apple He family / 379 Table 11-34 External disk drive connector signals for the Apple He Plus / 379 Table 11-35 Internal disk drive connector signals for the Apple lie / 381 Table 11-36 Internal disk drive connector signals for the Apple lie Plus / 381 Table 11-37 ACIA signal descriptions / 385 Table 11-38 Apple lie serial port connector signals / 387 Table 11-39 Apple lie Plus serial port connector signals / 387 Table 11-40 Mouse connector signals / 394 Table 11-41 Hand control connector signals / 398 Table 11-42 Memory expansion card connector signals / 404 Table 11-43 Apple lie Plus expansion connector signals / 405 Table 11-44 Apple He Plus internal modem connector signals / 406 A The 65C02 Microprocessor / 419 Table A-l Cycle time differences / 421 Figure and tables xxv B Address Map / 433 Table B-l Page $00 use / 435 Table B-2 Page $03 use / 439 Table B-3 Main memory screen hole allocations / 440 Table B-4 Auxiliary memory screen hole allocations / 443 Table B-5 Addresses $CO00-$CO3F / 444 Table B-6 Addresses $C04O-$CO5F / 446 Table B-7 Addresses $C060-$O07F / 447 Table B-8 Addresses $C080-$COAF / 448 Table B-9 Addresses $C0B0-$O0FF / 449 D Apple n-Famhy Differences / 455 Figure D-l Apple II, Apple II Plus, and Apple He hand control signals / 474 Table D-l Apple II-family identification bytes / 458 E USA and International Models / 477 Figure E-l USA standard (QWERTY or Sholes) keyboard, keyboard switch up / 479 Figure E-2 USA simplified (or Dvorak) keyboard, keyboard switch down / 481 Figure E-3 ISO version of USA standard keyboard, keyboard switch up / 482 Figure E-4 British keyboard, keyboard switch down / 483 Figure E-5 French keyboard, keyboard switch down / 484 Figure E-6 Canadian keyboard, keyboard switch down / 486 Figure E-7 German keyboard, keyboard switch down / 487 Figure E-8 Italian keyboard, keyboard switch down / 489 Figure E-9 Western Spanish keyboard, keyboard switch down / 491 Table E-l Keys and ASCII codes (hexadecimal) / 479 Table E-2 British keyboard code differences from Table E-l / 483 Table E-3 French keyboard code differences from Table E-l / 484 Table E-4 Canadian keyboard code differences from Table E-l / 486 Table E-5 German keyboard code differences from Table E-l / 487 Table E-6 Italian keyboard code differences from Table E-l / 490 Table E-7 Western Spanish keyboard code differences from Table E-l / 491 Table E-8 ASCII codes for the English (USA) character set / 493 Table E-9 Differences from English (USA) character set / 494 Table E-10 50 Hz power supply specifications / 494 xxvi Apple lie Technical Reference F Firmware Entry Points / 495 Table F-l Summary of firmware entry points / 496 Table F-2 Lo-Res graphics colors / 508 Table F-3 Values of Apple lie identification byte / 539 Table F-4 Escape sequences with RdChar / 569 Table F-5 Monitor modes / 609 G Conversion Tables / 6ll Figure G-l Bits, nibbles, and bytes / 613 Table G-l What a bit can represent / 613 Table G-2 Values represented by a nibble / 614 Table G-3 Hexadecimal/decimal conversion / 614 Table G-4 Hexadecimal to negative decimal conversion / 6l6 Table G-5 PIN digits / 618 Table G-6 Control characters / 620 Table G-7 Special characters / 621 Table G-8 Uppercase characters / 622 Table G-9 Lowercase characters / 623 H Controlling the Apple lie Plus Accelerator / 625 Table H-l Accelerator control word / 631 Figure and tables xxvii Preface About This Manual This is the reference manual for the Apple® lie and Apple He Plus personal computers. It contains descriptions of all the hardware and firmware that are used in the Apple He family, and provides technical information that hardware designers and programmers need when developing products to be used with Apple llc-family computers. The information in this manual is aimed at assembly-language programmers and experienced hardware designers, but others interested in the internal operation of the Apple He and Apple He Plus can also benefit from reading it. This preface describes the contents of this manual, and tells you how to obtain more technical information about Apple products. • xxix This manual tells you how the Apple lie-family members work, but not how to use them. If you need to know how to set up and use your Apple He or Apple lie Plus, read the owner's manual that came with the computer. This manual describes four versions of the Apple He: • the original Apple lie • the first version of the Apple lie that supports the UniDisk™ 3.5 drive • the first version of the Apple lie that supports the memory expansion card • the Apple He Plus More information on the various versions of the Apple lie is provided in Chapter 1. Contents of this manual The following is a brief outline of the contents of this manual. See the table of contents for a complete list of the subjects covered in each chapter; refer to the index to locate a specific piece of information. Chapter 1 introduces the Apple lie family, including external controls, connectors, and the main internal components, and explains the differences between the various versions of the Apple He. Chapter 2 describes the address space of the Apple lie-family members, discusses the way each computer's memory is organized, and explains how to access the various areas of memory. Chapter 3 discusses what happens when the Apple He or Apple He Plus is turned on or reset, and describes the use of interrupts in the Apple He family. Chapter 4 introduces the characteristics and features of the standard I/O firmware routines for the Apple lie family. Chapter 5 describes how programs can read the keyboard and use the speaker. Chapter 6 describes the firmware and memory features that allow your program to control the video display. xxx Apple He Technical Reference Chapter 7 describes the characteristics of the two serial ports and explains how your program can use these ports. Chapter 8 discusses the firmware routines that communicate with block devices such as disk drives and memory expansion cards, and includes descriptions of all the SmartPort calls that you can use to control the disk-drive interface. Chapter 9 describes the mouse port, including the different operating modes that you can select for the mouse, and how to read the mouse and hand controls. Chapter 10 describes the Apple lie family's built-in Monitor firmware. The Monitor helps you write, disassemble, and debug machine-language programs, as well as providing you with a means to look at and manipulate the contents of main memory. Chapter 11 describes the Apple lie-family hardware, including the power supply, all major components on the logic board, and all external and internal connectors. Appendix A describes the 65C02 microprocessor in detail, including the differences between it and the 6502 microprocessor used on eariier models in the Apple II family. Most of this appendix is a reprint of the manufacturer's data sheet for the 65C02. Appendix B contains an address map for the Apple He family, including detailed maps for memory pages $00 and $03, the screen holes, and the hardware page. Appendix C describes some of the operating systems and languages supported by Apple Computer for the Apple He family. Appendix D outlines the differences and similarities between the different members of the Apple II family of computers. Appendix E describes the various international versions of the Apple lie keyboard and character set. Power and safety information for international versions of the Apple He are also included in this appendix. Appendix F lists the firmware entry points for the Apple lie family ROM that are supported by Apple Computer, Inc. A description of the purpose and use of each entry point is included. Appendix G contains some tables that you might find useful, such as an ASCII table with binary, hexadecimal, and decimal equivalents, and hexadecimal to decimal conversion tables. The glossary defines many of the technical terms used in this manual. Preface: About This iManual xxxl Conventions used in this manual This section explains the typographic and terminology conventions used in this manual. Typographic conventions Special text in this manual is set off in several different ways, as shown in these examples. • Warning Warnings like this direct your attention to something that could cause injury, damage either software or hardware, or result in loss of data, A A Important Text set off like this contains information that is especially important, A A Original He Text set off like this—with the names of one or more computers in the left margin—applies only to the specified computer or computers, A • By the way: Information that is useful but incidental to the text is set off like this. You may want to skip over such information or return to it later. Specialized terms are printed in boldface when they arefirstdefined; these terms are defined in the glossary as well. Compute r v o i c e is used to indicate text that should be identical to your screen display or printout xxxii Apple He Technical Reference Notation and terminology conventions A dollar sign ($) before a number indicates that the number is in hexadecimal notation. For example, the hexadecimal equivalent of decimal 16 is written as $10. An asterisk (') after a signal name indicates that the signal is active low—that is, it is "on" when the signal is at a TTL low (0V) level The following abbreviations are used: KB kilobyte: 1,024 bytes Kbit kilobit: 1,024 bits MB megabyte: 1,024 kilobytes, or 1,048,576 bytes This book distinguishes between boards and cards as follows: a board is a permanent part of the computer (for example, the main logic board), whereas a card can be added or exchanged by the user to expand or reconfigure the system. r The two special function keys now called Command and Option have had other names in the past. The key with the outline of an apple on the keycap was originally called the Open Apple key, then the Apple key, and is now called the Command key. The versions of the Apple lie before the Apple He Plus have a key with a solid apple on the keycap; this key was originally called the Solid Apple Key, but is now called the Option key. On the Apple lie Plus, this key has Option on the keycap; there is no solid apple symbol on the keyboard. In this book, the names Command and Option are always used to refer to these two keys. How to get more information Several organizations exist that provide support for Apple II programmers and users. This section tells you how to contact the Apple Programmer's and Developer's Association (APDA™), Apple user groups, and Apple Developer Services. Preface: About This Manual xxxlit APDA APDA provides a wide range of technical products and documentation, from Apple and other suppliers, for programmers and developers who work on Apple equipment. For information about APDA, contact APDA Apple Computer, Inc. 20525 Mariani Avenue, Mailstop 33-G Cupertino, CA 95014-6299 800-282-APDA (800-282-2732) Fax:408-562-3971 Telex: 171-576 AppleLink: APDA User groups Ask your authorized Apple dealer for the name of the Apple user group nearest you, or call 800-538-9696. For information about starting your own user group, contact The Boston Computer Society One Center Plaza Boston, MA 02108 USA 617-367-8080 xxxiv Apple lie Technical Reference Apple Developer Services The Apple Certified Developer program is for professional hardware and software developers who plan to have a finished commercial product within 18 months. As a Certified Developer, you will receive monthly mailings including a newsletter, Apple II and Macintosh Technical Notes, pertinent Developer Program information, and all the latest news relating to Apple products. You will have access to Apple's Developer Hotline for general developer information. Once you are certified, Apple's Developer Technical Support staff can provide you with technical assistance. Apple's Technical Support engineers answer questions within 24 hours by electronic mail. For information about getting certified as an Apple developer, contact Apple Developer Services at the following address: Apple Developer Services Apple Computer, Inc. 20525 Mariani Avenue, Mailstop 27-S Cupertino, California 95014-6299 You will have to submit information on previous products and your present business plan along with your completed application. Preface: About This Manual Chapter 1 Introduction: The Apple He Family Several enhancements have been made to the Apple® lie computer since the original version was introduced in 1984. This chapter introduces the features of the different versions of the Apple He computer, including the latest member of the Apple He family, the Apple He Plus. • The first enhancement to the Apple lie provided support for the UniDisk™ 3.5 external drive, and included a set of ROM-based assembly-language routines called the Protocol Converter. The second enhancement of the Apple He included a new version of the Protocol Converter called the SmartPort, and support for an optional memory expansion card. The third enchancement, the Apple lie Plus computer, has a faster microprocessor than that used in earlier Apple lie computers, a 3.5-inch internal disk drive rather than the 5.25-inch internal disk drive used formerly, an internal power supply rather than the separate, external power supply used formerly, and a new keyboard. All versions of the Apple He are described in this manual. • Note: The Protocol Converter and SmartPort are different names for essentially the same built-in program mat handles input/output operations to peripheral devices like disk drives, hard disks, and tape backup machines. SmartPort is described in detail in Chapter 8. Where there are differences between the various versions of the Apple He, they are called out in the manual. For the sake of convenience, thefirsttwo enhanced versions of the Apple lie are identified by the new features they support: the UniDisk 3.5 Apple He and the memory expansion Apple He. Unless otherwise specified, all versions of the Apple lie operate identically. Software identification of an Apple lie An Apple II program can tell that it is running on an Apple lie by determining that the identification byte in location $FBB3 of ROM is equal to $06 and that the byte in location $FBC0 is $00. A program can tell which member of the Apple He family it is running on by checking the value of the identification byte in location $FBBF of ROM. Table 1-1 lists the versions of the Apple lie and their identification bytes. For the identification bytes to distinguish between all members of the Apple II family, see Table D-l in Appendix D. Apple lie Technical Reference Table 1-1 Apple lie-family identification bytes Machine $FBBF Apple lie (original) $FF Apple He (UniDisk 3.5) $00 Apple He (memory expansion) $03 Apple He (memory expansion, revised ROM) $04 Apple He Plus $05 • Checking the ID byte: You can use the PEEK command in Applesoft BASIC to check the values of the ID bytes. For example, to gel the value of the ID byte at $FBBF (64447 decimal), type PRINT PEEK ( 6 4 4 4 7 ) . Versions of the Apple He ROM There have been five versions of the Apple lie ROM so far. The ROM for the original Apple He assigned I/O devices to ports 1 through 6 (see the section "Port I/O," in Chapter 4); the mouse firmware entry points are assigned to port 4. A PR#7 command from Applesoft BASIC causes the original Apple lie to boot from the external 5.25-inch disk drive. The serial firmware in the original Apple lie does not support AppleTalk® or XON/XOFF protocol, and does not mask incoming line-feed characters. The original Apple lie can use 5.25-inch floppy disk drives only. The firmware in the UniDisk 3.5 Apple lie is functionally identical to that in the original Apple He except that the UniDisk 3-5 firmware • supports UniDisk 3.5 disk drives in addition to 5.25-inch disk drives • has AppleTalk firmware in port 7 • returns the message "AppleTalk Off Line" in response to a PR#7 command CHAPTER 1 • Introduction: The Apple lie Family • masks all incoming line-feed characters as a default setting • supports XON/XOFF protocol The firmware in the memory expansion Apple He is functionally identical to that in the UniDisk 3.5 Apple He except that the memory expansion firmware • supports an internal memory expansion (RAM disk) card assigned to port 4 • assigns the mouse to port 7 • has no AppleTalk firmware • cannot respond to a PR*7 command (if you try to execute a PR#7 command, the system hangs) The firmware in the revised memory expansion Apple He is functionally identical to that in the earlier memory expansion Apple He except that the revised firmware corrects a couple of minor bugs in the earlier firmware. The firmware in the Apple lie Plus is functionally identical to that in the memory expansion Apple lie except that the Apple lie Plus firmware • supports an internal 3.5-inch disk drive and external Apple 3.5-inch disk drives in addition to UniDisk 3.5 disk drives and 5.25-inch disk drives • supports the cache glue gate array (CGGA) and other hardware that enables the CPU to operate at up to 4 MHz Other differences between the various versions of the Apple He family computers are described in the following sections. The original Apple He The original Apple He is the first member of the He family. It has the following features: • a 65C02 microprocessor • 128 KB of RAM • a 5.25-inch internal disk drive Apple lie Technical Reference The outside of the original Apple He This section briefly describes the original Apple He keyboard, controls, indicators, and peripheral device connectors. The original Apple lie comes equipped with a keyboard, speaker (with audio output jack and volume control), internal disk drive, external power supply, and internal voltage converter. It also has built-in interfaces for a serial printer, a video monitor, special video display adapters, a modem, a mouse, and game controllers. These interfaces allow you to connect peripheral devices without having to go inside the machine to use expansion slots. Figure 1-1 shows the front and right side of an original Apple He, and Figure 1-2 shows the back and left side. CHAPTER 1 Introduction: The Apple He Family Figure 1-1 Original Apple He external features, front 6 Apple He Technical Reference Figure 1-2 Original Apple He external features, back The keyboard The primary input device of the original Apple is the keyboard, shown in Figure 1-3. The keyboard has a 62-key typewriter layout with both uppercase and lowercase characters and can generate ail 128 standard ASCII characters. A reset switch, 80/40-column display selector switch, keyboard layout selector switch, disk-use light, and power light are also located on the front of the computer. • Note: ASCII stands for American Standard Code for Information Interchange. It is a standard for assigning data values to letters, symbols, and numbers (that is, "encoding" them) so that a computer can handle them. Table 5-2 lists the ASCII encoding for the standard and simplified USA keyboard characters. Appendix E lists the encoding for international keyboards. CHAPTER 1 Introduction: Ihe Apple He Family Figure 1-3 Front of original Apple He with standard USA keyboard Power Light • Disk-Use Light — \ Keyboard Switch \ \ 80/40-Column Switch \, X \ Reset Switch '/resist I jjtaHO [I**—* n~i • • O D D D D E D D E • • • 0 P C • • • • • • • • (D • iiDiiziiDKDiaininiDiaiDigi DIDIDIDIDIDIDEIDID • El DBPOE Table 1-2 lists the characteristics of all original Apple lie keyboards and front panels, Apple He Technical Reference Operating features The original Apple He keyboard has automatic repeat on all character keys. This means that if you hold the key down longer than about a second, the character it generates repeats until you let up the key. It also has two-key rollover, which means if you press a key before releasing the one you pressed before it, the second character enters the computer as though you had released the previous key. • Table 1-2 Original Apple He keyboard specifications Number of keys 62 Character encoding ASCII Number of codes 128 Features Automatic repeat, two-key rollover Cursor movement keys Left Arrow, Right Arrow, Down Arrow, Up Arrow, Return, Delete, Tab Modifier keys Control, Shift, Caps Lock Special function keys Command (Open Apple), Option (Solid Apple), Esc (Escape) Front-panel switches Reset, 80/40 switch, keyboard switch Front-panel lights Power light, disk-use light Cursor movement keys The original Apple lie keyboard has four cursor movement keys with arrows marked on them: left, right, down, and up. Three other keys can also cause cursor movements: Return, Delete, and Tab. All seven of these keys generate ASCII control characters. It is up to the operating system or application program to interpret and act on the ASCII codes that these keys generate. The control characters and their corresponding control codes are shown in Table 5-2. Modifier keys Three special keys—Control, Shift, and Caps Lock—generate no codes when pressed by themselves, but change the codes generated by other keys with which they are pressed. CHAPTER 1 Introduction: The Apple He Family • Control, when pressed in combination with letter keys or certain other keys, produces ASCII control characters. Most applications do not display characters on the screen to correspond to control characters. • Shift works the same on the original Apple lie as on an ordinary typewriter: it selects uppercase letters and the upper characters on nonletter keys. • Caps Lock, in its down position, changes the letter keys to uppercase, but does not affect other keys. Special function keys The original Apple He keyboard has three special function keys: Command, Option, and Esc (Escape). The Command key is marked with the outline of an apple. The Option key is marked with a filled-in apple. The Command and Option keys do not have ASCII values; instead, they affect the values of fixed 1-bit locations in main memory. These addresses and their use are described in Chapters 5 and 9. The Esc key generates the ASCII escape (ESC) control character (key code $1B—see Table 5-2). This is the same character as generated by Control-left bracket (Control-!). When the Esc key is pressed, many programs—including the System Monitor in the Apple lie ROM—then interpret the keystrokes that follow as an escape sequence. Front panel switches Above the keyboard of the original Apple lie are three switches: Reset, the 80/40-column switch, and the keyboard layout switch. The Reset key has a direct line to the 65C02 microprocessor RESET signal line: holding down Control while pressing Reset causes the original Apple He to execute a warm start. See Chapter 3 for more details on resets and warm starts. You can restart the original Apple lie without turning the power off and back on again by holding down both Control and Command while pressing Reset. This procedure causes the original Apple lie to execute a forced cold reset. A forced cold reset puts the Apple He into the same state as if you had turned the power off and back on, without putting as much strain on the power supply as does the power-down/power-up sequence. 10 Apple He Technical Reference The 80/40-column switch on the keyboard of the original Apple lie lets you specify whether a program should display information in 40 or 80 columns per line. The switch indicates 40-column display when in its down position, and 80-column display when in its up position. A Important Not all programs check the 80/40 switch. Even programs that do check the switch may do so only when the program first starts up. If that is the case, changing the switch position while the program is running has no effect on the program's display. (See Table 5-1.) A You use the keyboard layout switch to select which of the two keyboard layouts and screen character sets built into your original Apple lie you want to use. On USA versions of the original Apple lie, you select the standard keyboard layout (known as the QWERTY or Sholes layout) (Figure 1-4) with the switch in the up position, and the Dvorak simplified layout (Figure 1-5) with the switch in the down position. The Apple He comes from the factory with the labels on the keycaps arranged in the Sholes positions, If you normally use the Dvorak keyboard layout and wish to change the keycaps, gently pry up the keycaps from the keyboard and rearrange and replace them in their Dvorak positions. CHAPTER 1 Introduction: The Apple He Family 11 Figure 1 4 Key assignments for original Apple He keyboard, with keyboard switch up (standard Sholes position) J reset j II&0/4Q Ij keyboard I disk use ipower / # $ % * & * ( } - + esc ; 2 3 4 5 6 7 8 9 0 - = delete f } 1 tab 0 W E R T Y (J 1 0 P [ ] \ SI control A s 0 F G H J K L • return < > •> shift 2 X C V B N M . . 1 shift caps loci d * *- ~> 4 f • 12 Apple lie Technical Reference Figure 1-5 Key assignments for original Apple lie keyboard, with keyboard switch down (Dvorak position); shaded characters may be in different positions on some models. reset J [J80/40 [Jkt keyboard I disk use Ipower esc / 2 3 4 5 6 7 8 9 0 [ } delete ti < > 7 + i i tab P Y F G C R L 1 — control A 0 E U 1 0 H T N S return shit) 0 J K X B M W V Z shfft caps \ lock d « <~ -4 4 T On international models, the labels on the keycaps indicate the character positions for the local keyboard layout, which is selected when the keyboard switch is down. When up, the keyboard switch selects the USA standard characters and key layout. The keyboard layouts and character sets for USA and international models of the original Apple lie are provided in Appendix E CHAPTER 1 introduction: The Apple lie Family 13 Disk-use and power lights The red disk-use light glows whenever the internal disk drive's motor is switched on, The green power light glows when the original Apple lie is turned on and normal power is present at the internal voltage converter of the original Apple lie. • Warning If the power light flashes on and off, turn off the computer immediately. Find out what caused the condition (such as a brownout or short circuit) and fix the problem before turning the computer on again. Above all, do not use the disk drive when the power light is flashing; doing so may damage the computer, A The volume control and audio output jack The original Apple lie has a built-in speaker that lets application programs produce a variety of sounds. There is a volume control on the left side of the original Apple lie case, and a jack for connecting headphones or an external speaker, as shown in Figure 1-6. The jack accepts either one-channel (monaural) or two-channel (stereo) plugs, although speaker output is monaural only. Inserting a plug disconnects the built-in speaker. Use of the speaker by application programs is explained in Chapter 5. 14 Apple He Technical Reference Figure 1-6 Apple He volume control and audio output jack Volume Control Knob Audio Output Jack Speaker (Inside) The door for the internal disk drive Disks are inserted and removed from the original Apple lie's internal disk drive via a door in the right side of the case (Figure 1-7). CHAPTER 1 Introduction: The Apple He Family 15 Figure 1-7 Internal disk drive door Disk Drive Door The back panel The back panel of the original Apple lie (Figure 1-8) has seven connectors and a main power switch. From left to right they are • a 9-pin D-type (DB-9) miniature connector for connecting hand controllers, a mouse, a joystick, or some other device (see Chapters 9 and 11) • a 5-pin DIN connector for serial input and output (port 2, normally for a modem) (see Chapters 7 and 11) • a 15-pin D-type (DB-15) connector for video expansion (see Chapter 11) • an RCA-type jack for a video monitor (see Chapter 11) • a 19-pin D-type (DB-19) connector for connecting one or more external devices, such as intelligent disk drives (see Chapters 8 and 11) 16 Apple He Technical Reference • another 5-pin DIN connector for serial input and output (port 1, normally for a printer or plotter) (see Chapters 7 and 11) • a special 7-pin DIN connector for power input (see Chapter 11) Before attaching cables to the original Apple He back panel connectors, be sure to move the handle until it clicks into position for propping up the computer, The handle should be down whenever the computer is running so that the computer can maintain proper cooling airflow. The installation manuals for external devices contain instructions for connecting them to the Apple lie. CHAPTER 1 .Introduction: The Apple He Family 17 Figure 1-8 Original Apple lie back panel connectors Power Switch External Power Connector Serial Port 1 Connector Mouse and.Hand Control Connector Serial Port 2 Connector Video Expansion Connector Video Output Connector External Disk Drive Connector Handle 18 Apple lie Technical Reference The external power supply The original Apple He computer comes with a separate external power supply that plugs into a 115-volt source (see Figure 1-9). The power supply provides 1.2 amps of current at +15 volts to the original Apple He. The internal voltage converter then converts the power to the voltages needed within the machine, The external power supply is described in more detail in Chapter 11. • Figure 1-9 Power supply and voltage converter Internal Voltage Converter Power Switch Power Supply The inside of the original Apple He Figure 1-10 shows the main components inside the original Apple He computer. CHAPTER 1 introduction: The Apple He Family 19 Figure 1-10 Inside the original Apple lie u esc 1 2 3 4 5 6 7 8 9 0 delete { } tab Q w E R T Y U 1 0 P I ] m control A s D F G H J K L j return < > shift Z X C V B N M * / shift caps 1 lock option l f~ -> i ? CHAPTER 1 Introduction: The Apple He family 33 ^ Figure 1-17 Key assignments for the Apple lie Plus keyboard, with keyboard switch down (Dvorak position) / reset I IIkafami j r V ™ g dai UM Ipa 1 1 •r •,. • •• # % f j { ) esc 1 2 3 4 5 6 7 0 9 0 dotefo [ } • < > • 9 + tab r P V F G C ff L 1 1 •< — control A 0 E U / D H r N S return shift 0 J K X B M w V Z s/iift •• caps 1 lock option 6 -. 1* Disk-use and power lights The disk-use and power lights work exactly the same on the Apple lie Plus as on earlier versions of the Apple He. 34 Apple lie Technical Reference The speaker The speaker in the Apple He Plus works the same way that the speaker in earlier versions does. However, the audio output jack is gone and the volume control is now positioned on the front of the computer, above the keyboard. The disk-access opening for the internal disk drive The disk-access opening for the internal disk drive is located in the same place as on earlier versions of the Apple He. A disk eject button is mounted on the left side of the opening; this button works only while the Apple lie Plus is switched on. In addition, software can eject disks from the internal 3.5-inch disk drive by issuing a Control call to the SmartPort firmware. • Figure 1-18 Apple lie Plus internal disk drive door Disk Drive Access Opening Disk Eject Switch CHAPTER 1 Introduction: The Apple He Family 35 The back panel The back panel of the Apple He Plus (Figure 1-19) has seven connectors and a main power switch. From left to right they are • a 9-pin D-type (DB-9) miniature connector for connecting hand controllers, a mouse, a joystick, or some similar device • a circular 8-pin mini-DIN connector for a modem or other serial device I/O • a 15-pin D-type (DB-15) connector for video expansion • an RCA-type jack for a video monitor • a 19-pin D-type (DB-19) connector for connecting one or more external peripheral devices, such as disk drives • a second circular 8-pin mini-DIN connector for a printer or other serial device I/O • a standard 3-pin connector for a power cord As for the original Apple He, you should move the handle of the Apple lie Plus until it clicks into position for propping up the computer before you attach cables to the back panel connectors. Keep the handle in this position whenever the computer is running so mat the computer can maintain adequate cooling airflow. 36 Apple lie Technical Reference Figure 1-19 Apple lie Plus back panel connectors Power Switch External Power Connector Serial Port 1 Connector — \ IMIMUMMII SA « is* CI a Mouse and Hand Control Connector J / —zf ~ Serial Port 2 Connector • Video Expansion Connector • Video Output Connector External Disk Drive Connector Handle The inside of the Apple nc Plus Figure 1-20 shows the main components inside the Apple He Plus computer. CHAPTER 1 Introduction: The Apple lie Family 37 Figure 1-20 Inside the Apple He Plus -r* H> 1 I i.Qi Power Supply Built-in Disk Drive • BIDIDIDIDIDIDIDIDIDIOHID iiainiDlDBiaiDiapiDloD ••••••••ODD •IDIDIDID1DIDIDID1DIE fe D • B Q 0 B The internal power supply The internal power supply operates from a 115 VAC input source. It provides the Apple He Plus with the standard Apple He DC voltages for the main logic board, the internal disk drive, up to three external disk drives, and the I/O signals available at the back panel. The internal power supply is shown in Figure 1-20. The standard DC voltages are ±12 volts and +5 volts. The -5 volt supply is generated on the main logic board. 38 Apple lie Technical Reference The main logic board The Apple He Plus main logic board is mounted on the bottom of the case, as for all of the earlier versions of the Apple He. Figure 1-21 shows the main logic board and the new integrated circuits in the Apple He Plus. The new circuits are • the 4 MHz 65C02 microprocessor • the 16 MHz crystal oscillator • the 84-pin accelerator IC, the cache glue gate array (CGGA) • the two 8 KB static RAMs for the accelerator circuit • the custom IC for the 3.5-inch disk drive logic circuit called the Multidrive Interface Glue (MIG) • the 2 KB static RAM for the 3.5-inch disk drive logic circuit The Apple He Plus main logic board also provides a connector for internal modems, and a faster microprocessor than that used in previous Apple He computers. In the Apple He Plus, the 65C02 runs at either 1 MHz or 4 MHz, and performs up to 2,000,000 8-bit operations per second. These components are described in Chapter 11. CHAPTER 1 Introduction: The Apple He Family 39 Figure 1-21 Apple lie Plus main logic boar I Speaker Data RAM TAG RAM 65C02 Microprocessor CGGA generator ROM IWM The other circuit boards The Apple He Plus contains other circuit boards that serve special purposes: a motor-speed control and read/write logic board for the disk drive, and a matrix board for detecting the position of keys pressed. This manual does not discuss these circuit boards. 40 Apple He Technical Reference Using the accelerator feature The Apple He Plus accelerator, consisting of the 4 MHz 65C02, the CGGA, and a RAM cache, allows the Apple He Plus to operate at a much faster speed than other Apple He computers. This increase in speed is achieved whenever the Apple He Plus is processing data or code that is in the RAM cache. Firmware corresponding to ports 1, 2, 5, and 6 always runs at 1 MHz, because the code for the serial ports and disk drives must run at this speed to operate correctly. Firmware for ports 3,4, and 7, on the other hand, can be cached and so potentially can run at 4 MHz. The user can disable the accelerator by holding down the Esc key while resetting the computer. When writing software for the Apple He Plus computer, you should keep in mind that the user can elect to run the program at either the normal speed of other Apple lie computers, or at the higher speed provided by the Apple lie Plus. Some programs might not work satisfactorily at the faster speed of the Apple lie Plus computer; for example, a game that reads a game paddle might not provide sufficient time for the user to act when running at the Apple lie Plus's fast speed. You can avoid this problem by writing programs that force the processor to run at 1 MHz during critical routines such as the one that reads the game paddle. See the sections "Enabling and Disabling the Accelerator" and "The ROM Wait Routine," in Chapter 11, for more information on controlling the speed at which the Apple He Plus processes code. The 65C02 microprocessor The 65C02 is a general-purpose 8-bit CMOS microprocessor similar in operation to the 6502 used in other members of the Apple II-family of computers. Figure 1-22 is a model of the 65C02 microprocessor's register organization. The 65C02 has one 16-bit register and five 8-bit registers. The 16-bit register is called the program counter (PC). It specifies the address in memory that contains the instruction the processor is currently carrying out. A 16-bit register can specify any one of 65,536 memory addresses, and so the 65C02 is said to have an address space of 65,536 locations. The five 8-bit registers in the 65C02 are the following: • The A register. The A register is like a desk top where the processor performs mathematical and logical operations on information. The A register is also called the accumulator. CHAPTER 1 Introduction: The Apple He Family 41 The Index registers, X and Y. The processor uses these registers to modify the address where information is to be found or placed, and to pass information from one program to another. A stack pointer, or S register. The stack is a portion of memory located in page $01 that the processor uses to temporarily store data. Several 65C02 instructions either push (store) the contents of a register onto the stack, or pull (retrieve) a byte from the stack and place it in a register. The S register keeps track of the next location in memory that will be used when one of these instructions is executed. A Processor Status register, or P register. Seven of the eight bits of this register are used as flags to record the outcome of processor activities, and can be checked by later instructions to determine what has happened and what the processor should do next. 42 Apple lie Technical Reference Figure 1-22 Internal model of the 65C02 microprocessor (© 1982 by NCR Corporation; used by permission) Regtiter Section Control Section RES IRQ NMI AO A1 A2 A3 A.I A5 • A6 ,\! Address . / BUS'S A8 ' A'! • A10 • All • A12- AI3 • AM • A15 • Data Bus CHAPTER 1 Introduction: The Apple He Family 43 Chapter 2 Address Map and Memory This chapter describes the address space in the Apple He and Apple lie Plus computers, and explains how to switch between different parts of memory. • 45 Overview of the address space The 65C02 processor's 16-bit address bus provides 216 unique addresses. If all of these addresses were dedicated to memory, the processor could directly address 65,536 bytes (64 KB) of RAM and ROM at one time. However, the addressing scheme used by the Apple lie family is somewhat more complex than a one-to-one correspondence between addresses and memory locations. For one thing, each Apple lie family member has 128 KB of RAM plus 32 KB of ROM (16 KB in the original Apple He) built in. In addition, the Apple He and Apple lie Plus computers use a portion of the address space to select devices and switch between portions of memory. Two of the devices selectable through address ranges are RAM and ROM; others are the asynchronous communication interface adapters (AClAs), the IWM, and various other ICs. Because this device-select scheme uses the memory-address lines, it is referred to as memory-mapped device selection. The hardware addresses that you can use are listed in Appendix B. A Apple He Plus A memory expansion card that connects to the internal connector in the Memory expansion memory expansion Apple lie or the Apple He Plus can contain up to 1 MB of RAM. Such a memory expansion card is addressed as a block device, however, not as memory. Block device I/O is discussed in Chapter 8. The memory expansion card manufactured by Apple Computer, Inc., for use in the memory expansion version of the Apple He computer, cannot be used in the Apple He Plus computer. For more information on the Apple memory expansion card, see the Apple Ik Memory Expansion Card Technical Reference, A In some cases, different functions have the same address—but not at the same time. The Apple lie and Apple He Plus control their shared addresses by using soft switches. For example, by using soft switches to select different portions of memory, a program can take advantage of the 128 KB of built-in RAM even though the address space of the 65C02 is only 64 KB. 46 Apple He Technical Reference • Note: A soft switch is an address that, when accessed, controls some aspect of the computer's operation. Whenever a soft switch is used in the Apple lie or Apple lie Plus to control a function, its use is described in this manual under the function that the switch controls. The soft switches that control address mapping are a major topic of this chapter. A contiguous block of 256 address locations in the 65C02 processor's address range is called a page. The address space of the 65C02 is divided into pages because the stack pointer and index registers are 8 bits wide, and an 8-bit register can specify only 256 different locations. Thus, page $00 consists of memory locations from 0 through 255 (hexadecimal $00 through $FF); page $01 consists of locations 256 through 511 (hexadecimal $0100 through $01FF); and so on. In this manual, all page numbers are given in hexadecimal format. There are 256 pages of 256 bytes each in the address space of the 65C02 processor. It takes two hexadecimal digits to represent 8 bits; therefore, the first two (high-order) digits of a four-digit hexadecimal address are the page number. Do not confuse this use of the term page with the terms Page I and Page 2, which are used to refer to portions of memory used to store video graphics data in the Apple He family. • Note.- All input and output in the Apple lie family is address mapped—that is, specific addresses (all in the $C0 page) are allocated to each I/O device. This chapter describes only the address spaces used for I/O. For details of the built-in I/O features and firmware, refer to the descriptions in Chapters 4 through 11. Address map Figure 2-1 is a map of the Apple lie family's address space; this figure shows the uses of each major block of addresses. As you can see in the figure, addresses $C000 through $C0FF are used only to access hardware, and addresses $C100 through $CFFF are used only to access ROM. All other addresses have multiple uses; each address may correspond to from two to six different locations in RAM or ROM. At any given time, each address corresponds to only one location in RAM or ROM; you use soft switches in the hardware page to control which address map the processor is currently using. CHAPTER 2 Address Map and Memory 47 A Original He The original Apple He has only 16 KB of ROM; the auxiliary ROM shown in Figure 2-1 is not present in the original Apple lie. A • Terminology: The terminology used to describe the memory organization in Apple II-family computers can be somewhat confusing. The first 64 KB of RAM is referred to as main RAM, and the second 64 KB is referred to as auxiliary RAM. The 47.5 KB of memory space from location $0200 through location $BFFF in both main and auxiliary RAM is referred to as the 48K address space. Together with pages $00 and $01, the 48K address space in main RAM corresponds to the entire RAM of the original Apple II and Apple II Plus computers. The memory space from $D0OO through $FFFF conesponds to the additional RAM added to the Apple II or Apple II Plus computers by a circuit card called the language card and is sometimes referred to as the language card or IC in the Apple lie family as well. The language card RAM comprises 16 KB of memory; however only 12 KB of address space is available for it (address locations $COO0 through $CFFF are reserved for hardware addresses and ROM). To provide a full 16 KB of address space for the language card RAM, the address space from $D000 through $DFFF can be switched between two different 4 KB portions of RAM in both main RAM and auxiliary RAM. These portions of RAM are referred to as Bank 1 and Bank 2, or sometimes as Language Card Bank I and Language Card Bank 2. The entire language card address space is referred to in this book as bank-switched memory; however, some people refer to only the $D0 page as bank-switched memory. To add to the confusion, the main RAM, auxiliary RAM, and ROM are sometimes referred to as memory banks. In this book, only Bank 1 and Bank 2 are referred to as memory banks. 48 Apple He Technical Reference Figure 2-1 Apple lie family address map Main RAM Auxiliary RAM Main ROM Auxiliary ROM r 'i l 1 . $FFFF o Monitor $F800 E a> 2 Applesoft 3.5" Disk BASIC Drivers $EOO0 2 Interpreter and Other °? Routines c Bankl Bank 2 Bankl Bank 2 03 $D000 - m I/O Firmware SC100 $CO0O 1 Hardware E? o E ID. CO -1- $0200 - $0000 Pages $00 and $01 CHAPTER 2 Address Map and Memory 49 Main RAM addresses ($00OO-$BFFF and $DOOO-$FFFF) The area labeled Main RAM in Figure 2-1 is the first 64 KB of RAM; this part of RAM corresponds to the RAM in an Apple He that does not have an Apple He Extended 80-Column Text Card installed. Auxiliary RAM addresses ($000O-$BFFF and $D000-$FFFF) The area labeled Auxiliary RAM in Figure 2-1 is the second 64 KB of RAM; this part of RAM corresponds to the RAM added to an Apple lie by the installation of an Apple He Extended 80-Column Text Card. The same set of addresses is used to access main RAM and auxiliary RAM; you use the memory selector soft switches to determine which portion of RAM is actually accessed. ROM addresses ($C100-$FFFF) ROM contains the firmware for an Apple lie-family computer. Addresses $C100 through $CFFF are used to access main or auxiliary ROM, depending on how the ROM selector soft switch is set. Addresses $DOO0 through $FFFF can access main ROM, auxiliary ROM, main RAM, or auxiliary RAM, depending on how the memory selector soft switches are set. Pages $C1 through $CF (addresses $C100 through $CFFF) of main ROM contain I/O firmware. The Apple lie-family I/O firmware entry points are allocated to ROM pages as follows: • Serial port 1 (RS-232 device) firmware entry points are in page $C1. • Serial port 2 (communication device)firmwareentry points are in page $C2. • Video output firmware entry points are in page $C3. • Mousefirmwareentry points are in page $C4 of the original Apple lie and the Unidisk 3.5 Apple He. 50 Apple lie Technical Reference • Memory expansion card entry points are in page $C4 of the memory expansion Apple He and the Apple lie Plus. • UniDisk 3.5 disk driver entry points are in page $C5 of the UniDisk 3.5 version and later versions of the Apple lie. In the Apple He Plus, the entry points for the Apple 3.5 disk driver are located in this page as well. • Disk II (5.25-inch disk drive) entry points are in page $03. • Mouse firmware entry points are in page $C7 in the memory expansion Apple He and in the Apple He Plus. • Note: The assignment of each I/O port's entry points to a particular page of memory gives each port the same entry points as it would have if the firmware were on a circuit card in a slot. In fact, programmers sometimes refer to the Apple lie-family I/O entry points as "slots," as in "serial port 1 is in slot 1 in the Apple lie." The address range of pages $D0 through $FF in main ROM contains the Applesoft BASIC interpreter and the Monitor firmware, allocated as follows: • Pages $D0 through $F7 (addresses $D000 through $F7FF) contain the Applesoft interpreter firmware. • Pages $F8 through $FF (addresses $F800 through $FFFF) contain the Monitor, described in Chapter 10. You can use some of the built-in Monitor routines to make input and output procedures in your assembly-language programs easier to write. The auxiliary ROM contains a variety of routines, including some routines for the mouse, the serial ports, the UniDisk 3.5 disk drive, and the Monitor. The auxiliary ROM also contains the SmartPort routines. In addition, in the Apple He Plus computer, the auxiliary ROM contains all of the disk driver routines for the internal 3.5-inch disk drive and external Apple 3.5 disk drives. • Warning There are no routines in auxiliary ROM that you a n use, and there is no way for your program to determine whether main or auxiliary ROM is switched in. Whereas die firmware in the UniDisk 3.5 and memory expansion Apple He computers would automatically return to the main ROM if you inadvertently toggled the ROM selector switch, in the Apple He Plus, all the space in auxiliary ROM is used and your program will crash if you make a call to auxiliary ROM. A CHAPTER 2 Address Map and Memory 51 Hardware addresses ($C00O-$C0FF) The soft switches that the Apple lie or Apple lie Plus and your programs use to control the computer's built-in input and output functions are all found in the $C0 address page (addresses $C000 through $C0FF). In the same range of memory are the switches for selecting blocks of memory throughout the address space. This chapter describes the address-space (memory) switches. Tables B-5 through B-9 in Appendix B list the hardware page addresses. The hardware functions of the switches in this page fall into five basic categories: • Data inputs. The only data input is location $C0OO, where the low-order 7 bits (bits 6 through 0) represent the keyboard key just pressed. (These data are guaranteed valid only when bit 7 is 1.) • Flag inputs. Most built-in input locations are single-bit flags in the high-order (bit 7) position of their respective memory addresses. Flags have only two values: on (greater than or equal to 128 or $80) or offQess than 128 or $80). The mouse button inputs and the keyboard any-key-down bit are examples of flag inputs. The locations for reading soft-switch states are also of this type. • Strobe outputs. The clear keyboard strobe (Chapter 5) and paddle timer strobe (Chapter 1) outputs are controlled by memory locations. If your program reads the contents of one of these locations, then the function associated with that location is activated. • Toggle switches. The Apple He family has two toggle switches: the speaker switch and the main/auxiliary ROM selector switch. A toggle switch has only one address assigned to it; each time you access it, it changes to its other state (on or off). The processor cannot read the status of these toggle switches. Reading the speaker switch activates the toggle once. However, if you write to the speaker switch location, the microprocessor activates the address bus twice during successive clock cycles, causing the toggle to end up in its original state. Therefore, you should read, rather than write, to use this switch. • Soft switches. Soft switches are two-position switches turned on by accessing one address and turned off by accessing another address. Most of these switches have a third address associated with them for reading the state of the switch. There are eight soft switches that select different combinations of bank-switched memory. Four of these eight switches require mat your program read them twice in succession to activate them. 52 Apple lie Technical Reference Bank-switched memory The memory areas described in this section are called bank-switched memory (see Figure 2-1) because so many distinct portions (banks) of memory—two portions of ROM and up to four portions of RAM—are accessed with the same group of addresses. Pages $00 and $01, at the low end of memory, are included here because the two sets of them—one in main RAM and one in auxiliary RAM—are controlled by the same switches as the high- address bank-switched memory. Page $00 and $01 are switched this way so that system software running in the bank-switched memory space can maintain its own zero page and stack independent of the 48K memory space. The soft switches used for selecting between main and auxiliary 48K memory space are discussed in the section "48K Memory," later in this chapter. Page allocations Pages $00 and $01 are used by many of the 65C02 instructions. The ROM and RAM addresses in bank-switched memory are usually occupied by system software such as interpreters, compilers, and operating systems. Page $00 (one-byte addresses) Several of the 65C02 microprocessor's addressing modes—for example, indirect addressing—require the use of addresses in page $00, or zero page. However, the Monitor, the interpreters, and the operating systems all make extensive use of page $00, too. One way to avoid conflicts is to use only those page-$00 locations not already used by these other programs. But there is another way. As you can see from Table B-l in Appendix B, page $00 is pretty well used up, except for a few bytes here and there. Rather than trying to squeeze your data into an unused comer, you may prefer a safer alternative: turn off interrupts, save the contents of part of page $00, use that part, then restore the previous contents to page $00, restore interrupts to their previous state, and then pass control to another program. CHAPTER.2 Address Map and Memory 53 Page $01 (the 65C02 stack) The 65C02 microprocessor uses page $01 as its stack—a place where it can store subroutine return addresses, in last-in, first-out (LIFO) sequence. Programs can also use the stack for temporary storage of registers (via push and pull instructions). However, programs should use the stack carefully. Pages $D0-$FF (ROM and RAM) The memory address space from locations $D000 through $FFFF is used for both ROM and RAM. The 12 KB of main ROM that can be accessed using these addresses contains the Monitor and the Applesoft BASIC interpreter. The auxiliary ROM in this address space contains SmartPort firmware, the disk driver for the internal 3.5-inch disk drive (Apple \k Plus only), and miscellaneous routines. The soft switches that you can use to control the area of memory accessed by these addresses are discussed in the following section, "Using Bank-Switched-Memory Selector Switches." The RAM in pages $D0 through $FF is normally used for storing computer languages, such as Pascal, or operating systems, such as ProDOS*. There are 16 KB of main RAM that can be accessed by addresses in the range $D000 through $FFFF. In order to accomplish this feat, the lower 4 KB of addresses (pages $D0 through $DF) serve double duty: depending on the setting of a soft switch, these addresses access one of two 4 KB blocks of main RAM. These two blocks of RAM are referred to as main RAM Bank I and main RAM Bank 2. There are also 16 KB of auxiliary RAM that can be accessed by addresses in the range $D0O0 through $FFFF. As for main RAM, the addresses in the range $D000 through $DFFF can be used to access two different 4 KB blocks of memory, referred to as auxiliary RAM Bank 1 and auxiliary RAM Bank 2. Using bank-switched-memory selector switches You select banks of memory in the same way you control other functions in the Apple lie family: by using soft switches. The bank-switched-memory selector switches do four things: • select whether the address range for bank-switched memory accesses RAM or ROM, or accesses ROM for reads and RAM for writes 54 Apple He Technical Reference • when RAM is selected for reads, either allow or inhibit (write-protect) writing to the RAM • when RAM is selected, select either main RAM or auxiliary RAM • select the first or second 4 KB bank of RAM in the address space $D00O through $DFFF • Note: There is also a selector switch to toggle between main and auxiliary ROM; however, there are no routines in auxiliary ROM that you can use, and switching to auxiliary ROM will cause your program to crash. • Warning Do not use soft switches without careful planning. Careless switching between RAM and ROM is almost certain to have catastrophic effects on your program. • Table 2-1 shows the addresses of the soft switches for selecting all allowed combinations of reading and writing in this memory space, and the addresses of the locations to read the switch settings. Figures 2-2 through 2-8 illustrate how to select the combinations and what the resulting status of each switch is. To make sure you do not inadvertently remove write protection from bank-switched RAM, the four write- enable addresses require that you read them twice in succession (indicated by RR in Table 2-1). Because the AltZP switch shares the read keyboard address, you must write (U7in Table 2-1) to its locations to change the switch setting. To find out which way a switch is set, read the appropriate location and then check bit 7 (this action is shown as Rl in Table 2-1). Note that there is no way to check whether write protection is on or off. A Important You can't read main RAM and write to auxiliary RAM (or vice versa); if you select either RAM for reading, you get that one for writing as well. However, you can read ROM and write RAM (Figures 2-3 and 2-4), which makes it easy to transfer firmware to bank-switched RAM if you want to use it with a program there, A CHAPTER 2 Address Map and Memory 55 Table 2-1 Bank-switched memory selector switches Name Action Hex Dec Function R/W $C02x 49184-49199 Toggle between main and auxiliary ROM' R $C030 49280 Read RAM; no write; use $D000 Bank 2 RR $C031 49281 Read ROM; write RAM; use $D000 Bank 2 R $C062 49282 Read ROM; no write; use $D000 Bank 2 RR $CD83 49283 Read and write RAM; use $D000 Bank 2 R $C088 49288 Read RAM; no write; use $D00O Bank 1 RR $C089 49289 Read ROM; write RAM; use$D000 Bank 1 R $C08A 49290 Read ROM; no write; use $D000 Bank 1 RR $C08B 49291 Read and write RAM; use $D0OO Bank 1 RdBnk2 Iff scon 49169 Read whether $D000 Bank 2 (1) or Bank 1 (0) RdLCRAM R7 $C012 49170 Read RAM ( l ) o r R O M ® AltZP W $C008 49160 Off: Use main RAM, page $00 and page $01 AltZP W $C009 49161 On: Use auxiliary RAM, page $00 and page $01 RdAltZP R7 $C0l6 49174 Read whether auxiliary (1) or main (0) RAM Switching to auxiliary ROM will cause your program to crash. 56 Apple lie Technical Reference Figure 2-2 Read ROM Battel memory: Select memory: W JC008 Tiirnntl AltZP W SC009 Turn on AltZP R SCOH2 Read ROM. use bank 2 ' R SC082 Read ROM. use bank 2* or R SC08A Read ROM, use bank 1 ' or R SC08A Read R n M , use bank |* ROM Main RAM Auxiliary RAM ROM Main RAM Auxiliary RAM i T "I I i 1 i :—~ .. £• o &/////// F V//////^ D yyyyyyyy i YS///S//' •n Oyyvy/y^ m ^yyyfty VyV^VSSs e U * . v/0y/y/ 09 yyys/ss; Bank Bank Bank Bank it 8ank Bank Bank Bank Y///S/// c <0 Vy/yyyyy 1 2 1 2 1 2 1 2 n Y//yyyf', - I Page $01 r Page $00 L Read resulting status: Read resulting status: R7 $C016 Read AltZP: bit 7 - 0 R7 $C016 Read AltZP: bit 7 - 1 R7 $C011 •ReadBar*2:bit7 - 1 orO R7 $C011 • Read Bank2; bit 7 - 1 or 0 P.7 $C012 Read EnLCRAM; bit 7 - 0 R7 $C012 Read EnLCRAM; bit 7 - 0 Legend: Read memory J — Inactive memory R7 - Read, check oil 7 RR - Read twice In succession Write memory R - Read W - Write CHAPTER 2 Address Map and Memory 57 Figure 2-3 Read ROM, write RAM, and use $D0OO Bank 1 Select memory Select memory W SC008 Turn oil AltZP W SC009 Turn on AltZP RR SC089 RR SC089 ROM Main RAM Auxiliary RAM ROM Main RAM Auxiliary RAM 1 1 r 1 I ^Bank> V $ ' $ V Bank 2 Bank 1 Bank 2 8ank l Bank 2 H ^Bank^ Bank 2 Page SOI [~_ Page $00 ™ Read resulting status Read resulting status: R7 SCO 16 Read AltZP Oil 7 0 R7 SC016 Read AltZP; bit 7 1 R7 SCO 11 Read 8ank2 bit 7 0 R7 SCOM Read Bank2. bit 7 0 R7 SCO 12 Reaa EnLCRAM. bit 7 R7 SC012 ReadEnLCRAM. Bit7 - 0 Legend: Read memory | Inactive memory R7 » Read, check bit 7 RR « Read Iwice in succession Write memoty R Read W Write 58 Apple lie Technical Reference Figure 2-4 Read ROM, write RAM, and use $D000 Bank 2 Select memory: Select memory. W SC008 Turn off AltZP W $C009 Turn on AltZP RR SC081 RR $C081 ROM Main RAM Auxiliary RAM Main RAM Auxiliary RAM 1 I 1 o E 2 Bank Bank Bank Bank 1 2 1 2 Page $01 T Page $00 C Read resulting status: Read resulting status: R7 JC01S Reed AltZP; bit 7 - 0 R7 $C016 Read AIIZP; bit 7 - 1 R7 $C011 Read Bank2; bit 7 - 1 R7 $C011 Read Bank2; bit 7 - 1 R7 $C012 Reivl EnLCRAM: bit 7 - 0 R7 SC012 Read EnLCRAM; bit 7 - 0 Read memory | ] - Inactive memory R7 - Read, check bit 7 RR - Read twice In succession Write memory R - Read W - Write CHAPTER 2 Address Map and Memory 59 Figure 2-5 Read RAM and use $D0O0 Bank 1 Select memory Select memory; W SC008 Turn ofl AllZP W SC009 Turn on AllZP R SC088 R SC088 ROM Main RAM Auxiliary RAM ROM Main RAM Auxiliary RAM I 1 1 I 1 I 1 1 I 1 m Bank Bank Bank Bank mm ZBank^: Bank 1 2 1 2 2 CD 1 1 I 1 Page $01 r Page $00 LT Read resulting slatus: Read resulting status: R7 SCO 16 Read AltZP. bit 7 = 0 R7 $C016 Read AltZP. bil 7 - 1 R7 SC011 Read Bank2. bit 7 = 0 R7 SCO n Read Bank2: bit 7 -. 0 R7 SC012 Read EnLCRAM; bit 7 = 1 R7 SC012 Read EnLCRAM. bit 7 = 1 Legend: Read memory j j = Inactive memory R7 = Read, check bit 7 RR • Read twice in succession Write memory R • Read W Write 60 Apple He Technical Reference Figure 2-6 Read RAM and use $D000 Bank 2 Select memory Select memory: W SC008 Turn off AMZP W SC009 Turn on AltZP R scoao R SC080 ROM Main RAM Auxiliary RAM ROM Main RAM Auxiliary RAM I 1 I 1 I 1 I 1 I 1 I 1 & m jp o E 0) o WW, i Bank ^Bank^ Bank Bank Bank Bank Bank 2 Banks in 1 1 2 1 2 1 c 9 CD i i Page $01 F Page $00 L Read resulting status: Read resulting status R7 SC016 Read AllZP: bit 7 - 0 R7 SC016 Read AllZP: bit 7 - 1 R7 SC011 Read Bank2; bit 7 - 1 R7 SC011 Read Bank2. bit 7 - 1 R7 SCO 12 Read EnLCRAM; bit 7 - 1 R7 SC012 Read EnLCRAM; bit 7 - 1 Legend: Read memory J • Inactive memory R7 - Read, check bit 7 RR - Read Iwice in succession Write memory R » Read W • Write CHAPTER 2 Address Map and Memory 61 Figure 2-7 Read and write RAM and use $D0O0 Bank 1 Select memory: Select memory: W SC008 Turn off AltZP W SC009 Turn on AltZP RR SCOBS RR SC08B ROM Main RAM Auxiliary R A M ROM Main RAM Auxiliary RAM 1 1 1 r 2- o E X 5 T) a E 1> % (J) S BankS Bank Bank Bank Bank Bank SBankX Bank ^B 2 1 2 1 x 1 j§ /fl<-«S Page $01 F•:•'•-•; •••*= ^','c , j . tv'-' Page$00 Q ^ . V :<%, y~."*.w»f? •' - -ri. Read resulting status: Read resulting status: R7 »C018 Read AltZP: bit 7 - 0 R7 $C016 Read AltZP; bit 7 - 1 R7 $C011 ReadBank2;bit7-1 R7 $C011 Read Bank2; bit 7 - 0 R7 SC012 Read EnLCRAM; bit 7 • R7 SC012 Read EnLCRAM; bit 7 • Legend: — Read memory j — Inactive memory R7 - Read, check bit 7 RR - Read twice In succession - Write memory R - Read W - Write 48K address space The 48K address space (which actually occupies 47.5 KB of address space) extends from location $0200 to location $BFFF (see Figure 2-9) in both main and auxiliary RAM. The amount of storage available for your use in this address space depends on what language or operating system you are using, and on what video display needs your program has. CHAPTER 2 Address Map and Memory 63 Page allocations Most of the Apple He family's 48K address space is available for storing your programs and data. However, a few memory pages are reserved for the use of the Monitor firmware, the Applesoft BASIC interpreter, and whatever video display you may select. A Important The system does not prevent your using these pages, but if you do use them, you must be careful not to disturb the system data they contain, A Page $02 (the input buffer) The GetLn input routine uses page $02 as its keyboard-input buffer. The size of this buffer (256 bytes) sets the maximum size of input strings read by Applesoft or the Monitor. If you know that you won't be typing any long input strings (more than, say, 30 characters), you can store temporary data at the upper end of page $02. Page $03 (global storage and vectors) The Monitor and operating systems use parts of page $03 for global storage and vectors. Table 3-1, in Chapter 3, shows the part of page $03 the built-in firmware uses. Table B-2 in Appendix B lists the complete contents of page $03. Pages $04-$07 (text and Lo-Res graphics Page 1) The most often used display buffer is text and Lo-Res graphics Page 1 (TLP1 in Figure 2-9), which occupies main memory pages $04 through $07. It is not usable for program and data storage if you are using Monitor routines or Applesoft, or with almost any other program that uses text or Lo-Res graphics display. 64 Apple He Technical Reference Figure 2-9 48K address map Main RAM Auxiliary RAM $FFFF I 1 Bank- Switched Memory | T J L ^ _, . $D00O f$CFFF /"• ROM/HW I $cooo $BFFF $6000 /^$5FFF" < HRP2 HRP2X CO T Hi-Res $4000_ Pages $3FFF HRP1 HRP1X <$2000 $1FFF~ f $OBFF TLP2 TLP2X Text and I $0800_ Lo-Res Pages'] $07FF TLP1 = TLP1X = I V. $0400_ { $0200 $01FF $0000 Main Memory Auxiliary Memory Screen Holes Screen Holes CHAPTER 2 Address Map and Memory 65 Text and Lo-Res graphics Page IX (TLP1X) is an identical display page occupying auxiliary memory pages $04 through $07. TLP1 and TLP1X are used together to produce 80-column text display. There are 128 locations in pages $04 through $07 (64 in main RAM, 64 in auxiliary RAM) that are not displayed on the screen. These locations are called screen holes. Tables B-3 and B-4 in Appendix B list the screen holes used by the Apple He family. • Warning The screen holes are reserved for use by the built-in firmware. If you use the screen holes, you might interfere with die operation of the firmware, A Pages $08-$0B (text and Lo-Res graphics Page 2) Text and Lo-Res graphics Page 2 (TLP2) occupies main memory pages $08 through $0B. Most programs do not use TLP2 for displays, but it is there for display use if required. Text and Lo-Res graphics Page 2X (TLP2X) is an identical display buffer occupying pages $08 through $0B in auxiliary memory. Note that Apple lie-family firmware does not provide a way to use the second pair of text and Lo-Res graphics pages for 80-column text display. Page $08 (communication port buffers) Serial port 2 uses the first half of auxiliary memory page $08 (addresses $0800 through $087F) as a keyboard input buffer, and the second half of the page (addresses $0880 through $08FF) as a serial input buffer. These buffers increase the data transfer rales possible with the serial communication port. See the section "Firmware Handling of Interrupts," in Chapter 3, for a description of how to use these features. If your program does not use this page for buffers, it can use it as part of TLP2X. 66 Apple lie Technical Reference Pages $20-$3F (Hi-Res graphics Page 1) The primary Hi-Res graphics display buffer, Hi-Res graphics Page 1 (HRP1), occupies the 32 memory pages from $20 through $3F (locations $2000 through $3FPF). If your program doesn't use Hi-Res graphics, this area is usable for programs or data. Hi-Res graphics Page IX (HRP1X) is an identical display page occupying auxiliary memory pages $20 through $3F. The Apple Ilc-family can display Double Hi-Res graphics by interleaving HRP1 and HRP1X. See the section "Graphics Modes," in Chapter 6, for a discussion of Hi-Res and Double Hi-Res graphics. Pages $40-$5F (Hl-Res graphics Page 2) Hi-Res graphics Page 2 (HRP2) occupies main memory pages $40 through $5F (locations $4000 through $5FFF). Most programs use this area for program or data storage, but it is also available as a second Hi-Res page. Hi-Res Page 2X (HRP2X) occupies auxiliary memory pages $40 through $5F. Apple Ilc-family firmware provides Hi-Res graphics routines for HRP1 and HRP2 only. Using 48K address space switches Two switches select whether addresses in the 48K address space access main or auxiliary RAM: RAMRd determines which to use for reading, and RAMWrt determines which to use for writing. When these switches are on, they select auxiliary RAM. When they are off, they select main RAM. (This discussion assumes that the 80Store switch, used to control display memory, is off.) See the section "Using Display Memory Switches," later in this chapter, for more information on these switches. Each switch has three locations assigned to it (see Table 2-2): one to turn it on, one to turn it off, and a third to read its state. Because the memory locations for turning the switches on and off are shared with keyboard reading functions, you must write to these addresses to use them for memory switching. For each switch, you can read bit 7 at the third location to check whether the switch is on or off. If the switch is on, bit 7 is 1; if the switch is off, bit 7 is 0. CHAPTER 2 Address Map and Memory 67 30U3J3J3H fEDtULpaj, o\\ a\6dy 89 eilJM - AA U Ajouieuj et|JAA - ^ ^Hq^oego'pBay _ iu AJOLUBLU BA|10BU| - AJOUIOUJ pBey — [%^/ 11 :pu«B«-| 0 - Z W 1UAAWVU Peey H 0 O $ Zd l - L m ^UAAWVd P ^ d H0O$ i d I = I jiq IpdtNVd Peey GtOO$ Zd 0 - z w :pdWVd pe»d EIOO$ Zd 0 - L JH 'aiojsOB Peed 810O$ Zd 0 - z JIQ :euois08 Peoy B100$ Zd :sn|B)s Oumnuoj puoy :snie|B Dumnsoj peed XlcfU'V r/yjtyp ^§ £x*ni / X Z d l l -^ ^V&ft& ,. 1.-. V ' ' r—r-H L..J..1 I 1 L J L J L J WVdAJB|||xnv wvb "IBW IWd A\iB|||xnv WVd "|BW AJOLUOLU u|uui oi oiMAA W>00$ AA /tioujoui AjEnixne o) eip/v\ S00O$ AA Ajouuew AjB|||xnB uio.ii pooy £000$ AA AJOLUOUI UIBLU UJOJI peed 2000$ AA 8JOJS08 H° " j n l 0000$ AA 8JOJS08 W° ujni 0000$ AA :/JOWOLU joeies :AJOUJOUI lOOjes SJicd ti|ds 'uorpstas ssajppB ^8^ OI-Z wn8lJ •3|JOM saupiiMS sqi Moq siEnsnrri \\-z puB QTZ S3jn8y '(9"Z 3IC1EJL) A\IOUI3UI AE|dsip 8urpn|3U] '38UEJ STtn in Xjouram rre ipjiMS oi jjo'aq isnm 3JOISO8 WON ( I ) -xnc X) (o) uiBUJ jSLpaqM peaa Z£16> woo$ m VAWVHPH WVH MS}' AjBtrpmB en 3 ] u ^ : u o ZSI6> S00O$ A UAWVH WVH J ^ UIEUI oi 31UA :JUO 95I6> wco$ yA UAWVH ( I ) -xne X) (o) q e i u ratjpqM. pean Wfr €100$ ^H PHNVHPH WVH 3 $ A^ijixnc pE3H :uo Sl# f(XD$ A PHWVH WVH M8fr " ! « " PE3H :jJO ^16> zooo$ A PHWVH nonatmj 33Q J«H tropsy mna ssqDiiAiS aoeds-ssajppu yfy fZ 3T^x Figure 2-11 48K address selection, one side only Select memory: Select memory: W $C0O0 Turn off BOStore W $C00O Turn off SOStore W $C002 Read from main memory W $C003 Read from auxiliary memory W $C004 Write to main memory W $C005 Write to auxiliary memory Main RAM Auxiliary RAM Main RAM Auxiliary RAM I 1 I _ U T -J !—.—I i i I I I J----H i—i—i HRP2X HRP2 HRP1X HRP1 •TLP2X •TLP2 •TLP1X •TLP1 u^___J AmfitoMliXxim •* • Read resulting status: Read resulting status: R7 $C018 Read BOStore; bit 7 - 0 R7 $C018 Read BOStore; bit 7 = 0 R7 $C013 Read RAMRd; bit 7 - 0 R7 $C013 Read RAMRd; bit 7 = 1 R7 $C014 Read RAMWrt; bit 7 - 0 R7 $C014 Read RAMWrt; bit 7 - 1 L«g«nd: | | — Inactive memory R7 - Read, check bit 7 — Read memory — Write memory R - Read W - Write Transfers between main and auxiliary memory If you want to write assembly-language programs that use auxiliary memory but you don't want to manage the auxiliary memory yourself, you can use the built-in 48K memory transfer routines, MoveAux and Xfer. These routines (listed in Table 2-3) make it possible to move between main and auxiliary memory without having to manipulate the soft switches described earlier in this chapter. CHAPTER 2 Address Map and Memory 69 A Important MoveAux and Xfer make it easier to use auxiliary memory, but they do not protect you from errors. You still have to plan your use of auxiliary memory to avoid catastrophic effects on your program, A • Table 2-3 48K address space transfer routines Name Action Hex Function MoveAux JSR $C3H Move data blocks between main and auxiliary 48K address space XFer JMP $C314 Transfer program control between main and auxiliary 48K address space Transferring data In your assembly-language programs, you can use the built-in routine MoveAux to copy blocks of data from main memory to auxiliary memory or from auxiliary memory to main memory. Before calling this routine, you must put the data addresses into byte pairs in page $00 and set or clear the carry bit to select the direction of the move. • Warning Don't try to use MoveAux to copy data in bank-switched memory (page $00, page $01, or pages $D0 through $FF). MoveAux uses page $00 during the copy. A. The pairs of bytes you use for passing addresses to this routine are called Al, A2, and A4, and they are used for parameter passing by several built-in routines. The addresses of these byte pairs are shown in Table 2-4. Put the addresses of the first and last bytes of the block of memory you want to copy into Al and A2. Put the starting address of the block of memory you want to copy the data to into A4. 70 Apple He Technical Reference Table 2-4 Parameters for MoveAux routine Name Location Parameter passed Carry 1 = Move from main to auxiliary memory. 0 = Move from auxiliary to main memory. AIL $3C Source starting address, low-order byte. A1H $3D Source starting address, high-order byte. A2L $3E Source ending address, low-order byte. A2H $3F Source ending address, high-order byte. A4L $42 Destination starting address, low-order byte. A4H $43 Destination starting address, high-order byte. • Note: The X, Y, and A registers are preserved. To copy data from main memory to auxiliary memory, set the carry bit (SEC instruction); to copy data from auxiliary memory to main memory, clear the carry bit (CLC instruction). When you make the subroutine call to MoveAux, the subroutine copies the block of data as specified by the A register and the carry bit. When it is finished, the A, X, and Y registers are just as they were when you called it. Transferring control You can use the built-in routine XFer to transfer control to and from program segments in auxiliary memory. You must set up three parameters before using XFer: the address of the routine you are transferring to the direction of the transfer, which zero page and stack you want to use (see Table 2-5). CHAPTER' 2 Address Map and Memory 71 Table 2-5 Parameters for XFer routine Name Location Parameter passed Carry 1 = Transfer from main to auxiliary memory. 0 = Transfer from auxiliary to main memory. Overflow 1 = Use page $00 and stack in auxiliary memory. 0 = Use page $00 and stack in main memory. $03ED Program starting address, low-order byte. $03EE Program starting address, high-order byte. • Note: The X, Y, and A registers are preserved. Put the transfer address into the two bytes at locations $03ED and $03EE, with the low-order byte first, as usual. The direction of the transfer is controlled by the carry bit: set the carry bit to transfer to a program in auxiliary memory; clear the carry bit to transfer to a program in main memory. Use the overflow bit to select which page $00 and stack you want to use: clear the overflow bit to use the main memory; set the overflow bit (cause an overflow condition) to use the auxiliary memory. After you have set up the parameters, pass control to the XFer routine by a jump instruction, rather than a subroutine call. A Warning It is your responsibility as the programmer to save the current stack pointer before using XFer and to restore it after regaining control. Failure to do so will cause program errors. Refer to "Interrupts" in Chapter 3 for instructions on how to do this, A Using display memory switches Selection of main or auxiliary RAM for the 48K address space is described earlier in this chapter. However, under many circumstances your program may want to control reading and writing to display pages separately. The switches discussed in this section override the effects of RAMRd and RAMWrt for display pages only. 72 Apple He Technical Reference Three switches are involved in the display page selection process. Each of them has three locations assigned to it: one to turn it on, one to turn it off, and a third to read its state (see Table 2-6). One of the switches, 80Store, shares its on and off addresses with a keyboard reading function. As a result, your program must write to these locations to turn the switch on and off. • Table 2-6 Display memory switches Name Action Hex Dec Function 80Store w $C000 49152 Off: RAMRd and RAMWrt determine RAM locations. 80Store w $C001 49153 On: Page2 switches between TLP1 and TLP1X, and (if HiRes on) between HRP1 and HRP1X. Rd80Store R7 $0018 49176 Read whether 80Store on (1) or off (0). Page2 R $C054 49236 Off: Select TLP1 and HRP1. Page2 R $C055 49237 On: If 80Store off, switch to TLP2, and (if HiRes on) to HRP2. If 80Store on, switch to TLP1X, and (if HiRes on) to HRP1X. RdPage2 R7 $C01C 49180 Read whether Page2 on (1) or off (0). HiRes R $C056 49238 Off: Display text and Lo-Res graphics page. HiRes R $0057 49239 On: Display Hi-Res pages; make Page2 switch between Hi-Res pages. RdHiRes R7 $C01D 49181 Read whether HiRes on (1) or off (0). IOUDis w $O07E 49278 On: Disable IOU access for addresses $C058 to $C05F; enable access to DHiRes switch*. lOUDis w $C07F 49279 Off: Enable IOU access for addresses $C058 to $C05F; disable access to DHiRes switch'. RdlOUDis R7 $C07E 49278 Read IOUDis switch (l=off)t. D HiRes R/W $C05E 49246 On: (If IOUDis on) turn on Double Hi-Res. D HiRes R/W $C05F 49247 Off: (If IOUDis on) turn off Double Hi-Res. RdDHiRes R7 $C07F 49279 Read DHiRes switch (l=off)t • The firmware normally leaves IOUDis on. f Reading or writing any address in the range $C070-SC07F also triggers the paddle timer and resets the VBL interupt flag (see Chapter 9). CHAPTER 2 Address Map and Memory 73 For each switch, you can read bit 7 at the third location to check whether the switch is on or off. If the switch is on, bit 7 is 1; if the switch is off, bit 7 is 0. Here is how these switches work for reading and writing: • If HiRes is off, then Page2 switches between text and Lo-Res graphics pages (TLP) only. If HiRes is on, then Page2 switches between TLP and Hi-Res graphics pages (HRP). • If 80Store is off, RAMRd and RAMWrt (described in Table 2-2) determine whether main or auxiliary RAM locations are used. Page2 selects pages for display (as described in Chapter 6), but not for reading and writing. • If 80Store is on, it overrides RAMRd and RAMWrt with respect to the display pages selected by HiRes and Page2 (see Figures 2-12 and 2-13). • Figure 2-12 Page2 selections, 80Store on and HiRes off Select memory: Select memory: W $C0O1 Turn on BOStore W $C001 Turn on SOStore R $C056 Turn off HiRes R SC05G Turn oft HiRes R $C054 Turn off Page2 R SC055 Turn on Page2 Main RAM Auxiliary RAM Main RAM Auxiliary RAM I 1 I 1 I 1 r I I , 1 i I 1_—| HRP2X Hi-Res Graphics Pages HRP1X L Text and Lo-Res r~ •TLP2X Graphics Pages L run •TLP1X i i Read resulting status: Read resulting status: R7 $C018 Read BOStore; bit 7 = 1 R7 $C018 Read BOStore; bit 7 = 1 R7 $C01D Read HiRes; bit 7 - 0 R7 $C01D Read HiRes; bit 7 - 0 R7 $C01C Read Page2; bit 7 - 0 R7 $C01C Read Page2; bit 7 - 1 Legend: V — R = Read 4y\ Read memory J — Inactive memory [IIIIIH Controlled by RAMRd and W - Write ^^| " Write memory WWII " RAMWrt (See Figs. 2-12 and 2-13) R7 = Read, check bit 7 74 Apple He Technical Reference Figure 2-13 Page2 selections, 80Store on and HiRes on Select memory: Select memory: W $C001 Turn on SOStore W $C001 Turn on 80Store R $C057 Turn on HiRes R $C057 Turn on HiRes R $C054 Turn off Page2 R $C055 Turn on Page2 Main RAM Auxiliary RAM Main RAM Auxiliary RAM I 1 I I I I '• i 1 i i i i I 1 1 I , 1 i i i i i i I I i I 1 1 i—'—i I 1 I i i i HRP2X HRP2 HRP2X Hi-Res Graphics llllllll Pages llllllllil HRP1X HRP1 |HRPIX> - Text and Lc—Res i— •TLP2X • TLP2 s TLP2X Graphics Pages U ;i 11111111111, in 1111 n in, •TLP1X TLP1 11 11 TLP1X I ___-! .._— Read resulting status: Read resulting status: R7 $C018 Read BOStore; bit 7 = 1 R7 $C018 Read BOStore; bit 7 = 1 R7 $C01D Read HiRes; bit 7 - 1 R7 $C01D Read HiRes; bit 7 - 1 R7 $C01C Read Page2; bit 7 - 0 R7 $C01C Read Page2; bit 7 - 1 Legend: R - Read Read memory • ' = Inactive memory Controlled by RAMRd and W - Write Write memory RAMWrt (See Figs. 2-12 and 2-13) R7 - Read, check bit 7 CHAPTER 2 Address Map and Memory 75 Chapter 3 Resets and Interrupts This chapter describes resets and interrupts in the Apple He and Apple He Plus computers. The first half of the chapter explains how to start up and reset the computer and what happens in hardware and firmware when you do so. The second half of the chapter describes 65C02 interrupts, and explains how interrupt handlers are used on the Apple Ilc-family computers. • 77 Starts and resets After the reset signal (RESET') to the 65C02 processor is asserted, the processor goes through an initialization sequence, then loads into the program counter the address of a routine in ROM called the system reset handler. As shown in Figure 3-1, the system reset handler puts all hardware devices and soft switches into a known state, and then checks the reset vector. The address of the system reset handler is stored at locations $FFFC and SFFFD in ROM. The system reset handler is located at SFA62. Table 3-1 shows the address of the reset vector and of other vectors located in page $03. A Warning All of the firmware in the Apple Ilc-family computers assumes that, after a reset, the system is in the state set by the system reset handler. If you change the pointer at SFFPC and SFFFD to point to your own reset handler, the system will almost certainly crash. • If the reset vector is valid, the system reset handler passes control to the program pointed to by the reset vector. If the reset vector is not valid, the reset routine attempts to load an operating system, and then passes control to that operating system. There are three ways to reset the Apple He or Apple He Plus: • power-on reset (cold start) • forced cold-start reset (forced cold reset) • warm-start reset (warm start) Each of these methods calls the reset routine. 78 Apple He Technical Reference • Figure 3-1 Reset routine flowchart /Command-Control-Reset\ f Power on /Control-Reset V (Forced cold restart) ) I (Cold start) I (Warm start) I Set initial state of machine and sound the speaker rtppiesou^ Restart program with variables intact Yes, Reset \ProDOS „ vector Restart Applesoft Other Do what it says to do Write trash into first 2 bytes of each page of memory Clear screen; display name of machine; load reset vector and power-up byte; initiate disk startup procedure Operating Load in operating Run Applesoft; Yes. Yes. no operating (system available) system (I/O hooks on disk? not yet loaded) system rNO Display message; Load I/O hooks turn off disk motor; and rest of run Applesoft operating system; run program CI IAPTER 3 Resets and Interrupts 79 Table 3-1 Page $03 vectors Vector address Vector function $03F0(1008) Address of the subroutine that handles BRK instructions (normally $FA59) $03F1 (1009) $03F2(1010) Reset vector (see text) $03F3(1011) $03F4(1012) Validity-Check byte (see text) S03F5O013) Jump instruction to the subroutine that handles Applesoft & commands (normally S4C $58 $FF) S03F6 (1014) $03F7(1015) $03F8(1016) Jump instruction to the subroutine that handles user Control-Y commands $03F9(1017) $03FA(1018) $03FB(1019) Not used in the Apple lie family (contains jump instruction to the subroutine that handles nonmaskable interrupts) $03FC(1020) $03FD (1021) $03FE (1022) Interrupt vector (address of the subroutine that handles interrupt requests) $03FF (1023) The Initial state of the machine When you initiate a reset, hardware and firmware in the Apple He family set the machine to the following initial state: • main memory ROM and RAM are enabled • auxiliary RAM is disabled • bank-switched memory space is set to read from ROM and write to RAM • main RAM Bank 2 is enabled 80 Apple He Technical Reference Next, the reset routine performs the following steps: I. It displays the contents of 40-column text Page 1 using the primary character set. 2 It sets the display window equal to the full 40-column display. 3 It puts the cursor at the bottom of the screen. 4. It sets the text display formal to normal. 5. It sets the keyboard as the standard input device. 6. It sets the display as the standard output device. 7. It masks mouse interrupts. 8 It sets mouse defaults (described in Chapter 9). 9. It turns on the IOUDis memory switch, which enables access to the DHiRes switch. 10. It sets DHiRes off. II. In the Apple lie Plus only, it sets ports 1, 2, 5, and 6 to operate at 1 MHz and ports 3,4, and 7 to operate at 4 MHz (see following note). 1Z It clears the keyboard strobe. 13. It beeps the speaker. A Apple He Plus When the Apple lie Plus computer executes the restart procedure, the processor is set to run at 4 MHz, unless the user holds down die Esc key while resetting the computer. If the user holds down the Esc key while pressing Control-Command-Reset or pressing Control-Reset, then the Apple lie Plus is set to run at 1.023 MHz (the same speed as other Apple He computers). The Apple He Plus accelerator feature is discussed in more detail in Chapter 11. A Memory selector soft switches and the various address maps used by the Apple He family are described in Chapter 2. Standard I/O devices are described in Chapter 4. Mouse defaults are described in Chapter 9. With the computer in a known state, the reset routine uses the Validity-Check byte at location $03F4 to determine if the reset vector is valid, as described in the next section. CHAPTER 3 Resets and Interrupts 81 The reset vector The reset routine determines from the reset vector which application to load upon reset. The reset vector is valid only after a cold reset has already been completed. If the reset vector is valid, the computer performs the warm-start procedure; if the reset vector is not valid, the computer performs the cold-start procedure. The reset routine uses the Validity-Check byte and the high-order byte of the reset vector (together referred to as the power-up bytes) to determine if the reset vector is valid. When the cold-reset routine, operating system, or application sets a reset vector, it also sets the Validity-Check byte by performing an exclusive OR (XOR) operation on the high-order byte of the reset vector (at $03F3) and the constant 165 (hexadecimal $A5). The reset routine checks the reset vector for validity by performing an XOR operation on the high-order byte of the reset vector and the constant 165. The result of this XOR operation is compared with the value stored in the Validity-Check byte. If the values match, the reset routine considers the vector to be valid and precedes with the warm-start procedure. If they do not match, the reset routine considers the vector to be not valid and precedes with the cold-start procedure. • Note.- You can change the reset vector so that the reset routine transfers control to your program (the user reset handler) when the user performs a warm-start. For this to work, you must also change the Validity- Check byte to equal the result of performing an operation XOR on the high-order byte of your new reset vector and the constant 165 ($A5). If you fail to do this, then the next time the user resets the Apple lie or Apple He Plus, the reset routine will determine that the reset vector is not valid and will execute the cold start procedure, eventually transferring control to the disk bootstrap routine or to Applesoft. You can use the SelPwrC subroutine to generate the Validity-Check byte for the current reset vector. This subroutine is at location $FB6F. When your program finishes, it can return the Apple He or Apple He Plus to normal operation by restoring the original reset vector and again calling the SetPWRC subroutine to set the Validity-Check byte. 82 Apple He Technical Reference The cold-start procedure The cold-start procedure can be initiated in one of two ways: • power-up reset (turning on your Apple He or Apple He Plus) • forced cold reset (see "Forced Cold Reset," later in this chapter) A cold start is executed whenever a reset has been initiated and the Validity-Check byte is not valid. With the computer in a known state, the reset routine clears the display and puts the string A p p l e 11 c or A p p l e l i e + at the top of the display. It then loads $03F2 and $03F3 (the reset vector) with the Applesoft interpreter entry point address and calculates the Validity-Check byte, loading $03F4 with the result. With the Validity-Check byte loaded, the reset routine attempts to load an operating system from a startup device. The reset routine passes control to the entry point for the device that has the highest priority. Block 0 of the device is read into location $0800 in main memory. If location $0800 contains $01 and location $0801 is nonzero, the device is considered to contain valid startup code. If there is valid startup code in the device, control is passed to code starting at location $0801, and the program or operating system code loaded begins running. If there is no valid startup code in the device, control is returned to the reset routine. The reset routine then tries the entry point for the device with the next highest priority, following exactly the same steps. This procedure is repeated until valid startup code is found or until all devices capable of booting the computer have been tried. In the event no valid startup code is found, the reset routine prints the message Check Disk Drive at the bottom of the screen. A Apple He Plus The Apple He Plus computer reset routine prints the message u n a b l e to F i n d a B o o t a b l e D i s k O n l i n e at the bottom of the screen. A • Note-. If you press Control-Reset before the startup procedure is completed, the reset routine passes control to the Applesoft BASIC interpreter. The priorities assigned to startup devices, and the boot-device entry points, depend on the version of the Apple He. The startup configurations for all Apple He family members are given in the following sections. CHAPTER 3 Resets and Interrupts 83 A Important DOS and versions of Pascal earlier than 1.3 do not support the multiple-device startup protocol; you must use ProDOS, Pascal 1.3 (or later), or a similar operating system to take advantage of this protocol, A To start up the computer from a specific disk drive rather than using the reset handler's priority scheme, use one of the following methods: • issue a PR#n command from BASIC to jump to $CnOO • issue a n Control-P command from the Monitor to jump to $CnOO • execute a JMP instruction in a program to jump to $CnOO The number n is the port number of any device that contains valid startup code; for example, PR#6 causes the Apple He to boot from the internal 5.25-inch disk drive and causes the Apple He Plus to boot from the first external 5.25-inch disk drive. The memory expansion Apple He and the Apple He Plus can be booted from a properiy formatted memory expansion card by using 4 for n. When you turn on the computer or press Command-Control-Reset, the computer attempts to start up from the highest-priority device, then tries the other startup devices in a preset sequence. When you jump to a particular port, on the other hand, the computer attempts to start up from the device at that port only. If the computer fails to find valid boot code at the port you specified, it displays an error message on the screen and passes control to the Applesoft interpreter in ROM. Original Apple He The original Apple He has one internal 5.25-inch disk drive and supports one external 5.25-inch drive. Only the internal 5.25-inch disk drive can be used as a startup device for a cold start. The internal disk drive entry point is $C600 in the main ROM (port 6, drive 1). The routines at $C600 turn on the drive motor, recalibrate the read/write head at track 0, and read sector 0. The data read from track 0, sector 0 of the startup disk is then loaded and executed. • Note: It is possible to load the original Apple He from the external 5.25-inch drive, but it can only be done from either the Monitor or BASIC. The procedures are as follows: • from the Monitor, press 7 Control-P • from Applesoft, type P R # 7 84 Apple lie Technical Reference UniDisk 3.5 Apple lie The UniDisk 3.5 Apple lie has one internal 5.25-inch disk drive, and supports one external 5.25-inch drive and one external 3.5-inch disk drive. The possible startup devices for the UniDisk 3.5 Apple lie are, in order of priority, as follows: • internal 5.25-inch disk drive at $C600 (port 6, drive 1) • external 3.5-inch disk drive at $C500 (port 5, drive 1) All addresses are for the main ROM. The routines at $C500 and at $C600 turn on the drive motor, recalibrate the read/write head at track 0, and read sector 0. The data read from track 0, sector 0 of the startup disk is then loaded and executed. • Note: The UniDisk 3.5 Apple lie cannot start up from the external 5.25-inch drive (port 6, drive 2). Memory expansion Apple He The memory expansion Apple lie has one internal 5.25-inch disk drive, and supports up to three external devices plus a memory expansion card. The external devices can be any combination of up to three external 3.5-inch disk drives and one external 5.25-inch disk drive. The possible startup devices for the memory expansion Apple He are, in order of priority, as follows: • memory expansion card at $C400 (port 4, drive 1) • internal 5.25-inch disk drive at $C600 (port 6, drive 1) • external UniDisk 3.5 drive at $C500 (port 5, drive 1) All addresses are for the main ROM. The routines at $C400 call the SmartPort Read Block routine. The Read Block routine reads block $00 from the memory expansion card and loads it into main memory. CHAPTER 3 Resets and Interrupts 85 A Important A memory expansion card cannot start up the memory expansion Apple lie after a power-up reset, as the contents of the expansion RAM are erased when the power is switched off. Memory expansion cards are discussed in the section "Memory Expansion Card," in Chapter 11. A The routines at $C500 and at $C600 turn on the drive motor, recalibrate the read/write head at track 0, and read sector 0. The data read from track 0, sector 0 of the startup disk is then loaded and executed. • Note: The memory expansion Apple He cannot start up from either the external 5.25-inch disk drives (port 6, drive 2 and port 2 drive 1) or the second external 35-inch disk drive (port 5, drive 2). Apple lie Plus The Apple He Plus has one internal 3.5-inch disk drive, and supports up to three external drives plus the memory expansion card. The external drives can be any combination of one Apple 3.5 drive, up to three UniDisk 3.5 drives, and up to two 5.25-inch disk drives. The possible startup devices for the Apple lie Plus are, in order of priority, as follows: • memory expansion card at $C400 (port 4, drive 1) • internal 3.5-inch drive at $C500 (port 5, drive 1) • external UniDisk 3.5 or Apple 3.5 drive at $C500 (port 5, drive 2) • external 5.25-inch drive al SC600 (port 6, drive 1) All addresses are for the main ROM. • Note.- The hardware and firmware of the Apple He Plus computer can support up to five disk drives, but the power supply supports only four (counting the internal disk drive). The routine at $C400 calls the SmartPort Read Block routine. The Read Block routine reads block $00 from the memory expansion card and loads it into main memory. 86 Apple He Technical Reference A Important The memory expansion card cannot start up the Apple He Plus after a power- up reset, as the contents of the expansion RAM are erased when the power is switched off. A The routines at $C500 and $C600 turn on the drive motor, recalibrate the read/write head at track 0, and read sector 0. The data read from track 0, sector 0 of the startup disk is then loaded and executed. • Note: The Apple He Plus cannot start up from the second external 5.25-inch disk drive (port 6, drive 2), nor can it startup from the second or third external 3.5-inch disk drives (port 2, drive 1 and port 2, drive 2). Forced cold reset You can initiate the forced cold reset procedure by pressing Control-Command-Reset. A forced cold reset is a way to force the Apple He or Apple He Plus to execute a cold start without turning the computer off and back on. A forced cold reset is useful if you want to terminate a program unconditionally or bail out of some sort of programming problem. • Note: On all Apple He family members but the original Apple He, you must hold the Command key (Open Apple on older Apple He computers) down until the internal drive starts to spin. If you release the Command key before the drive starts to spin, the computer drops into BASIC instead of rebooting. In addition to the normal initialization performed by all resets, a forced cold reset "destroys" the contents of main memory by writing 2 bytes of meaningless data into the beginning of each page of main RAM. The reset vector at $03F2 and $03F3 is destroyed in the process. Then the reset routine loads the reset vector with the Applesoft interpreter entry point address and calculates the Validity-Check byte, loading $03F4 with the result. With the Validity-Check byte loaded, the reset routine attempts to load an operating system from a startup device, just as for a power-on reset. See the section "The Cold-Start Procedure," earlier in this chapter, for details. CHAPTER 3 Resets and Interrupts 87 A Important Whenever possible, you should use a forced cold reset to terminate processing instead of turning the power off and on; it is much less stressful to the computer hardware. (Notice, however, that if you have a memory expansion card configured as a startup disk, the only way to achieve a complete reset and avoid restarting from the memory expansion card is to turn the power off and back on.) A • Note: If you press both the Command key and the Option key (the Solid Apple key on older Apple He computers) during power-up or a forced cold restart, built-in diagnostic code is executed. The warm-start procedure A warm start is executed whenever a reset has been initiated and the Validity-Check byte is valid. With the computer in a known state, the reset routine passes control to the routine pointed to by the user reset vector, which points to the controlling program or operating system. The controlling program restarts and operates normally. What the controlling program or operating system does when it restarts depends on the specific program or operating system. As long as nothing has been done to alter the reset vector or the Validity-Check byte since power-up, the reset vector is still considered valid, and it points to the Applesoft interpreter. The reset routine passes control to Applesoft through the reset vector and Applesoft restarts your program, with your variables intact. If the reset vector has been altered by an application program or operating system, the Validity-Check byte must also have been altered to match the new vector address. If the Validity-Check byte has not been set correctly, then the validity check fails and the reset routine initiates the cold-start procedure. If you are using DOS or ProDOS, the reset vector has been altered to point to the operating system in use and the Validity-Check byte has been altered to match. In this case, the reset routine passes control through the altered reset vector to the operating system in use at the beginning of the reset procedure. 88 Apple tic Technical Reference The user can initiate a warm reset by pressing Control-ReseL An application program or operating system can initiate a reset by jumping to the reset routine. The vector to the reset routine is at locations $FFFC and $FFFD in ROM; this vector normally points to the system reset handler at $FA62. A Important A program residing only in bank-switched RAM cannot use the reset vector to regain control after a reset because upon reset the hardware selects the ROM for reading in the bank-switched memory space, A Interrupts An Interrupt is a signal to the processor that indicates that the computer should slop whatever it's doing so it can quickly handle a lime-dependent task. For example, the Apple He mouse sends an interrupt to the computer every time it moves. This lets the system keep track of the mouse's position and maintain smooth movement of the pointer on the screen. • Warning If you use interrupt hardware directly, instead of using the built-in interrupt- handling firmware, you can't be sure that your programs will be compatible with possible future Apple H-series computers or revisions. • Introduction When an interrupt occurs, control passes to an interrupt handler, which must record the exact state of the computer at the moment of the interrupt, determine the source of the interrupt, and take appropriate action. It is important that the computer preserve a "snapshot" of its state when interrupled, so that when it continues later wilh what it was doing, those conditions can be restored. CHAPTER 3 Resets and Interrupts 89 Interrupts have not always been fully supported on the Apple II. All versions of Apple's DOS, as well as the Monitor program, rely on the integrity of location $45; however, the built-in interrupt handler in the Apple II Plus and original Apple He computers destroys the contents of this location by saving the A register (accumulator) in it. Most versions of Pascal do not work on these machines with interrupts enabled. The Apple He-family built-in interrupt handler saves the A register (accumulator) on the stack instead of in location $45. DOS 3.3, ProDOS, Pascal 1.2 (or later versions), and the Monitor all work with interrupts on the Apple lie family. A Important Because interrupt requests that occur while interrupts are disabled cannot be detected, interrupts are effective only if they are enabled most of the time. Because of the critical timing of disk read and write operations, Pascal, DOS 3.3, and ProDOS disable interrupts while accessing the disk. Thus it is important to remember that while a disk drive is being accessed, all the interrupts discussed in this chapter are disabled, A Interrupt handling on the 65C02 From the point of view of the 65C02, there are three possible causes of interrupts. 1. The IRQ' line on the microprocessor can be pulled low. If 65C02 interrupts are not masked (that is, the CLI instruction has been used), the CPU can respond to an IRQ interrupt. This is the standard technique that devices use when they need immediate attention. 2 The processor executes a break instruction (BRK, opcode $00). 3 A nonmaskable interrupt (NMI) occurs. Because the NM1' line in the 65C02 of the Apple lie and Apple lie Plus computers is not used, this never happens. The first two possibilities cause the 65C02 to save the current program counter and status byte on the stack and then jump to the routine whose address is stored in $FFFE and $FFFF. The sequence performed by the 65C02 is as follows: 1. If an IRQ interrupt occurs, finish executing the current instruction. 2 Push the high byte of the program counter onto the stack. 3 Push the low byte of the program counter onto the stack. 90 Apple He Technical Reference 4 Push the program status byte onto the stack. 5. Jump to the address stored in $FFFE, $FFFF—that is, JMP ($FFFE). The different sources of interrupt signals are discussed below. The interrupt vector at $FFFE In the Apple He family there are three separate regions of memory that can be accessed by address $FFFE, depending on how the soft switches are set: • the built-in ROM • the bank-switched memory in main RAM • the bank-switched memory in auxiliary RAM The vector at $FFFE in the ROM points to the built-in interrupt handling routine. You should use the built-in interrupt handler, rather than writing your own, because of the complexity of interrupts in the Apple He family. When you initialize the mouse or serial communication firmware, copies of the ROM's interrupt vector are placed in the interrupt vector addresses in both main and auxiliary bank-switched memory. If you plan to use interrupts and the bank-switched memory without the mouse or communication firmware, you must copy the ROM's interrupt vector yourself. The built-in interrupt handler The built-in interrupt handler is responsible for determining whether a BRK or an IRQ interrupt occurred. If it was an IRQ interrupt, the handler decides whether the interrupt should be handled internally, handled by the user, or simply ignored. The handler records the current memory configuration, then sets up its own standard memory configuration so that a user's interrupt handler knows the precise memory configuration when it is called. Next the handler checks to see if the interrupt was caused by a break instruction, and if it was, handles it as described later in this chapter. CHAPTER 3 Resets and Interrupts 91 If the interrupt was not caused by a BRK instruction, the handler checks for interrupts that it knows how to handle (for example, a properly initialized mouse) and handles them. Depending on the state of the system, it either ignores other interrupts or passes them to a user's interrupt-handling routine whose address is stored at $03FE and $03FF in main memory. After handling an interrupt itself, or after the user's handler returns an RTI instruction, the built-in handler restores the memory configuration, and then executes an RTI instruction to reactivate processing. Table 3-2 illustrates this whole process. Each of the steps is explained in detail in the sections that follow. • Table 3-2 Interrupl-handling sequence Interrupted User's program Processor Built-in handler handler Program •^ Push address Push status JMP($FFFE)- Save old and set new memory configuration If BRK, then go to break handler (SFA47) Our interrupt? NO: Push address Push status JMP($03FE)~ • > - Handle interrupt YES: Handle it Restore memory- RTI configuration Pull status Program ^ - Pull address 92 Apple lie Technical Reference Saving the memory configuration The built-in interrupt handler saves the state of the system and sets it to a known state according to these rules: • If 80Slore and Pagc2 are on, then it switches in text Page 1 (Page2 off) so that main screen holes are accessible. It switches in main memory for reading (RAMRd off). It switches in main memory for writing (RAMWrt off). It switches in ROM addresses $D000-$FFFF for reading (RdLCRAM off). It switches in main stack and zero page (AltZP off). It preserves the auxiliary stack pointer and restores the main stack pointer. It preserves the current ROM state and switches in the ROM bank 1. A Important Because main memory is switched in, all memory addresses used later in this chapter are in main memory unless otherwise specified, A Managing main and auxiliary stacks Because the Apple lie family has two stack pages, the firmware has established a convention that allows the system to be run with two separate stack pointers. Two bytes in the auxiliary stack page are to be used as storage for inactive stack pointers: $0100 for the main stack pointer when the auxiliary stack is active, and $0101 for the auxiliary stack pointer when the main stack is active. When a program that uses interrupts switches in the auxiliary stack for the first lime, it should place the value of the main stack pointer at auxiliary stack address $0100, and initialize the auxiliary stack pointer to $FF (the top of the stack). When it subsequently switches from one stack to the other, it should save the current stack pointer before loading the pointer for the other stack. When an interrupt occurs while the auxiliary stack is switched in, the current stack pointer is stored at $0101, and the main stack pointer is retrieved from $0100. Then the main stack is switched in for use. After the interrupt has been handled, the stack pointer is restored to its original value. CHAPTER 3 Resets and Interrupts 93 User's interrupt handler at $03FE You can set up screen hole locations to indicate that the user's interrupt handler should be called when certain interrupts occur. To do this, place your interrupt handler's address at $03FE and $03FF in main memory, low byte first. The user's interrupt handler should do the following: • Verify that the interrupt came from the expected source. The following sections describe how this should be done for each interrupt source. • Handle the interrupt as desired. • Clear the interrupt, if necessary. The following sections describe how to clear the interrupts. • Return with an RTI instruction. If your interrupt handler needs to know the memory configuration at the time of the interrupt, it can check the encoded byte stored 4 bytes down on the stack. This byte is explained later in this chapter. In general there is no guaranteed maximum response time for interrupts. This is because the system may be doing a disk operation, which could last for several seconds. Once the built-in interrupt handler has been called, it takes about 250 to 300 microseconds for it to call your interrupt-handling routine. After your routine returns, it takes 40 to 140 microseconds to restore memory and return to the interrupted program. If memory is in the standard state when the interrupt occurs, the total overhead for interrupt processing is about 150 microseconds less than if memory is in the worst possible state (80Store and Page2 on, auxiliary memory switched in for reading and writing, auxiliary bank-switched memory page $02 switched in for reading and writing). 94 Apple He Technical Reference Handling break Instructions After the interrupt handler has set the memory configuration, it checks to see if the interrupt was caused by a BRK (opcode $00) instruction. (If it was, bit 4 of the processor status byte is a 1.) If so, it jumps to a break- handling routine, which saves the state of the computer at the time of the break as shown in Table 3-3. The break routine then jumps to the routine whose address is stored at $03F0 and $03F1. • Table 3-3 Break handler state-saving format Information Location Program counter (low byte) $3A Program counter (high byte) $3B Encoded memory state Accumulator $45 X register $46 Y register $47 Status register $48 The encoded memory state in location $44 is defined as shown in Table 3-4. • Table 3-4 Encoded memory state definition Bit Definition 1 if alternate zero page and stack switched in 6 1 if 80Store and Page2 both on 5 1 if auxiliary RAM switched in for reading 4 1 if auxiliary RAM switched in for writing 3 1 if bank-switched RAM being read 2 1 if bank $01 of page $D000 switched in 1 1 if bank $02 of page $D000 switched in 0 1 if auxiliary ROM switched in CHAPTER 3 Resets and Interrupts 95 Sources of interrupts The CPU can receive interrupts from many different sources. Each source is enabled and used slightly differently from the others. There are two basic sources of interrupts: use of the mouse and actions affecting the two 6551 ACIA circuits (the chips that control serial communication). How to use these sources of interrupts in conjunction with the built-in interrupt handler is discussed later in this chapter. Mouse use can cause interrupts when • the mouse is moved in the horizontal (X) direction • the mouse is moved in the vertical (Y) direction • the mouse button is pressed Interrupts can also be generated every 1/60 second by the rising edge of the vertical blanking signal (VBL). This is called the vertical blanking interrupt (VBL interrupt) and is synchronized with a signal used for the video display. Actions affecting the ACIA circuits can cause interrupts when • a key is pressed (the firmware can use this interrupt to buffer keystrokes, or it can pass the interrupt on to the user) • either ACIA has received a byte of data from its port (the firmware can use this interrupt to buffer data or it can pass the interrupt on to the user) • pin 5 of either serial port changes state (device ready/not ready to accept data) (when the serial firmware is active, this interrupt is absorbed; however, the serial firmware uses the signal to decide whether or not to transmit the next byte of data) • either ACIA is ready to accept another character to be transmitted (when the serial firmware is active, this interrupt is absorbed; however, the serial firmware uses the signal to decide whether or not to transmit the next byte of data) • the keyboard strobe is cleared (the firmware absorbs this interrupt) An interrupt can also be generated by a device attached to the external disk drive port. The firmware can pass this interrupt on to the user. 96 Apple He Technical Reference Firmware handling of Interrupts The following sections discuss how the various sources of interrupts should be used together with the built-in interrupt handler. Firmware for mouse and VBL Interrupts As described in Chapter 9, the mouse can be initialized (by the SetMouse call) to eight different modes that enable one or more sources of interrupts. In transparent mode, the interrupts are entirely handled by the built-in interrupt handler; the other modes require a user-installed interrupt handler. A Apple lie Plus Using the mouse in vertical blanking active modes causes the Apple He Plus computer to run at 1 MHz regardless of the speed set at power-up or reset. When you use the mouse in transparent mode, on the other hand, the Apple He Plus can run at 4 MHz. A When the mouse is initialized, the interrupt vector is copied to addresses $FFFE and $FFFF in main and auxiliary bank-switched RAM. This permits mouse interrupts with any memory configuration. When the mouse is active, possible sources of interrupts are those listed earlier in this chapter as resulting from mouse use. When an interrupt occurs, the built-in interrupt handler determines whether that particular interrupt source was enabled (by the SetMouse call). If so, the user's interrupt handler, whose address is stored at $03FE, is called. The user's interrupt handler should first call ServeMouse to determine the source of the interrupt. This call updates the mouse status byte at $077C and returns with the carry bit clear if mouse movement, button, or vertical blanking was the source of the interrupt. The values of this mouse status byte at $077C (S077F in the memory expansion Apple He) are as follows: Bit 1 Means that 3 Interrupt was from vertical blanking 2 Interrupt was from button 1 Interrupt was from mouse movement CHAPTER 3 Resets and Interrupts 97 If the interrupt was due to mouse movement or button, the user's interrupt handler should then do a call to ReadMouse. This causes the mouse coordinates and status to be updated as follows: $047C Low byte of X coordinate $04FC Low byte of Y coordinate S057C High byte of X coordinate $05FC I ligh byte of Y coordinate $077C Button and movement status Bit Means 7 0 = button up; 1 = button down 6 0 = button up on last ReadMouse 1 = button down on last ReadMouse 5 0 = no movement since last ReadMouse 1 = movement since last ReadMouse 3-1 Always set to 0 (interrupt cleared) After the interrupt has been handled, the routine should terminate with an RTI instruction. Remember that interrupts may be missed during disk accesses. If you turn on mouse interrupts without initializing the mouse, the built-in interrupt handler takes care of the interrupts and your program never knows they occurred. If you want to handle mouse interrupts yourself, you must write your own interrupt handler and place vectors to it at addresses $FFFE and $FFFF in bank-switched RAM, and set bit 7 of the mouse port mode byte. See the section "Movement Interrupt Mode," in Chapter 9, for more information on this feature. Interrupts will be ignored whenever the $DO00-$FFFF ROM is switched in. Firmware for keyboard interrupts The Apple Ilc-family hardware is able to generate an interrupt when a key is pressed. The firmware is able to buffer up to 128 keystrokes, completely transparently, when properly enabled to do so. It saves them in the second half of page $08 of auxiliary memory. After the buffer is full, subsequent keystrokes are ignored. Because interrupts are only generated when keypresses occur, characters generated by the auto-repeat feature are not buffered. They can, however, be read when the buffer is empty. Once keyboard buffering has been turned on, the next key should be read by calling RdKey ($FD0C). 98 Apple lie Technical Reference A Warning Do not call the buffer-reading routine directly. Its entry address will not be the same in future versions of the computer. • The special characters Control-S (stop list) and Control-C (stop Applesoft execution) do not work while keyboard buffering is turned on. Use Option-Control-X to clear the buffer. Using keyboard buffering firmware Keyboard buffering is automatically turned on when the serial firmware is placed in terminal mode. Otherwise you must turn it on yourself this way: 1. Disable processor interrupts (SEI). 2 Set location $05FA to $80. This tells the firmware to buffer keystrokes without calling the user's interrupt handler. 3 Set locations $05FF and $06FF to $80. These are pointers to where in the buffer the next keystroke will be stored and where the next will be read from, respectively. 4. Turn on the ACIA for port 2 by setting the low nibble of $C0AA to the value $0F. For example: LDA SCOAA Read port 2 ACIA command register ORA #$OF Set low nibble to $0F STA $COAA Set port 2 ACIA command register If you are using the serial ports al the same time, just set the low bit of $C0AA to 1. This prevents receiver interrupts from being turned off. A PR#2 or IN#2 command or the equivalent shuts off keyboard interrupts. 5. Enable processor interrupts (CLI). A Apple He Plus The memory expansion Apple lie and the Apple He Plus use some of the Memory expansion screen holes differently than earlier Apple He computers. For the memory expansion Apple He and Apple lie Plus, change all $nnnF addresses to SnnnC (for example, change $05FF to $05FC). A CHAPTER 3 Resets and Interrupts 99 Using keyboard interrupts through firmware Keyboard interrupts are received through the ACIA for port 2. They can be enabled as follows: 1. Disable processor interrupts (SEI). 2 Set location S05FA to SCO. This tells the firmware to identify a keystroke interrupt and to call the user's interrupt handler. 3 Turn on the ACIA for port 2 by setting the low nibble of SCOAA to the value $0F. For example: LDA $CQAA Read port 2 ACIA command register ORA #$OF Set low nibble to $0F STA $COAA Set port 2 ACIA command register 4. Enable processor interrupts (CLI). When the user's interrupt handler is called, it can identify the keyboard as the interrupt source by reading location $04FA. This is a copy of the ACIA status register at the time of the interrupt. If the interrupt was due to something on the ACIA for port 2, bit 7 is set. If the interrupt was caused by a keystroke, bit 6 is set and bit 5 is unchanged. After servicing this interrupt, the interrupt handler should clear the interrupt by setting $04FA to $00. Using external Interrupts through firmware Pin 9 of the external disk drive connector (EXTINT) can be used to generate interrupts through the ACIA for port 1. A Apple lie Plus The EXTINT signal is not available on pin 9 of the Apple He Plus computer. The external disk drive connectors are described in the section "Disk I/O," in Chapter 11. A 100 Apple He Technical Reference The EXTINT signal can be used as a source of interrupts (on a high-to-low transition) if enabled as follows: 1. Disable processor interrupts (SEI). 2 Set location $05F9 to $C0. This tells the firmware to identify an external interrupt, and to call the user's interrupt handler. 3 Turn on the ACIA for port 1 by setting the low nibble of $C09A to the value $0F. For example: LDA SCO9A Read port 1 ACIA command register ORA # s o F Set low nibble to $0F STA sco9A Set port 1 ACIA command register 4. Enable processor interrupts (CL1). When the user's interrupt handler is called, it can identify this interrupt by reading location S04F9. This is a copy of the ACIA status register al the time of the interrupt. If the interrupt was due to something on the ACIA for port 1, bit 7 is set. If the interrupt was caused by the external interrupt line, bit 6 is clear and bit 5 is unchanged. After servicing this interrupt, the interrupt handler should clear the interrupt by setting $04F9 to $00. Firmware for serial interrupts The Apple Ilc-family hardware is able to generate interrupts both when the ACIA receives data and when it is ready to send data. The built-in interrupt handler responds to incoming data only. The firmware is able to buffer up to 128 incoming bytes of serial data from either serial port. After the buffer is full, subsequent bytes are ignored. Only one port can be buffered at a time. The following sections assume that the serial port to be buffered is already initialized, as explained in Chapter 7. CHAPTER 3 Resets and Interrupts 101 Using serial buffering transparently Serial buffering is automatically turned on when the serial firmware is placed in terminal mode. Otherwise you must turn it on yourself, as follows: 1. Disable processor interrupts (SEI). 2 Set location S04FF to $C1 to buffer port 1, or to $C2 to buffer port 2. 3. Set locations $057F and $067F to $00. These are pointers to the next byte in the buffer to be used and the next character to be read from the buffer, respectively. 4 Turn on the ACIA for the port by setting the low nibble of SC09A for port 1 or $C0AA for port 2 to $0D. For example: LDA $CO9A Read port 1 ACIA command register AND SFO Clear low nibble ORA #SOD Set low nibble to $0D STA sco9A Set port 1 ACIA command register The 0 in bit 1 of the command register enables receiver interrupts; thus an interrupt is generated when a byte of data is received. 5. Enable processor interrupts (CLI). A Memory For the memory expansion Apple He, change all $nnnF addresses to $nnnC and expansion change $0D to $09. A When serial port buffering is thus enabled, normal reads from the serial port firmware fetch data from the buffer rather than directly from the ACIA. 102 Apple He Technical Reference Using serial interrupts through firmware It is also possible to use the firmware to call the user interrupt handler whenever a byte of data is read by the ACIA. In this mode buffering Ls not performed by the firmware. 1. Disable processor interrupts (SEI). 2 Set location $04FF to a value other than $C1 or $C2. 3. Turn on the ACIA for the port by setting the low nibble of $C09A for port 1 or SCOAA for port 2 to $0D. For example: LDA sco9A Read port 1 ACIA command register AND $FO Clear low nibble ORA #SOD Set low nibble to SOD STA sco9A Set port 1 ACIA command register The 0 in bit 1 of the command register enables receiver interrupts; thus an interrupt is generated when a byte of data is received. 4. Enable processor interrupts (CLI). A Memory For the memory expansion Apple He, change all $nnnF addresses to $nnnC and expansion change $0D to $09. A When a serial port is thus enabled, the user's interrupt handler is called each time the port receives a byte of data. The status byte saved by the firmware (S04F9 for port 1; S04FA for port 2) has the high bit set if the interrupt occurred on that port. Bit 3 is set if the interrupt was due to a received byte of data. The interrupt handler should clear the interrupt by clearing bits 7 and 3 of that port's status byte ($04F9 for portl;$04FAforport2). Transmitting serial data The serial firmware does not implement buffering for serial output. Instead it waits for two conditions to be true before transmitting a character: • The ACIA's transmit register must be ready to accept a character. This is true if bit 4 of the ACIA's status register is 1. CHAPTER 3 Resets and Interrupts 103 • The device must signal that it is ready to accept data. This is true if bit 5 of the ACIA's status register is 0. Bit 5 is 0 if pin 5 of the port's connector is also 0. When the serial firmware is active, a change of state on pin 5 of that port generates an interrupt. That interrupt is absorbed, but the data remains in bit 5 of the status register. Interrupts from the ACIA's transmit register are normally disabled. A loophole in the firmware So that programs can make use of interrupts on the ACIAs without affecting mouse interrupt handling, there is a tiny loophole purposely left in the built-in interrupt handler. If transmit interrupts are enabled on the ACIA— that is, if bits 3, 2, and 0 of the ACIA's command register have the values 0,1, and 1, respectively—then control is passed to the user's interrupt handler if the interrupt is not intended for the mouse (movement, button, or VBL). This means that you can write more sophisticated serial interrupt-handling routines than the limited firmware space could provide (such as printer spooling). The firmware will still set memory to its standard state, handle mouse interrupts, and restore memory after your routine is finished. When you receive the interrupt, neither ACIA's status register has been read. You are fully responsible for checking for interrupts on both ACIAs, determining which of the four interrupt sources on each ACIA caused the interrupt, and how to handle them. Refer to the 6551 specification for more details. The built-in firmware itself is an excellent example of how interrupts on the ACIA can be handled. Bypassing the interrupt firmware The following sections give further details on using interrupts on the Apple Ilc-family computers without using the built-in interrupt handler. A method of handling mouse interrupts directly is described in Chapter 9. 104 Apple He Technical Reference Using mouse Interrupts without the firmware To use mouse interrupts without the firmware, as mentioned above, you must set your own interrupt vectors. If the $D000-$FFFF ROM is ever switched in, the built-in interrupt handler absorbs the mouse interrupts. Tables 3-5 and 3-6 show how to activate and read mouse interrupts without using the firmware. Remember to disable interrupts (SEI) before enabling mouse interrupts, then turn them on again when done (CLI). • Table 3-5 Activating mouse interrupts Disable IOU To activate interrupts on Enable IOU access Select source Enable source access Mouse X (rising edge) STA $C079 STA $C05C STASC059 STASC078 Mouse X (falling edge) STA$C079 STA $C05D STA SC059 STA SC078 Mouse Y (rising edge) STA $C079 STA $C05E STA $C059 STA$C078 Mouse Y (falling edge) STA SC079 STA SC05F STA$C059 STA SC078 VBL STA $C079 STA $C05B STA SC078 Table 3-6 Reading mouse interrupts To read interrupts Read direction from (A.S.AJ9 Determine source Handle It Return Mouse X LDA$C066 LDA SCO 15 (bit 7=1 if true) RTI Mouse Y LDA$C067 LDA SCXI17 (bit 7=1 if true) RTI VBL LDA $C019 (bit 7=1 if true) RTI The mouse direction data read from $C066 and $C067 are guaranteed valid for at least 40 microseconds, and average duration is at least 200 microseconds, so you should read the direction as soon as possible. CHAPTER 3 Resets and Interrupts 105 Using ACIA Interrupts without the firmware To use ACIA interrupts without the firmware, you must set your own interrupt vectors. If the $D000-$FFFF ROM is ever switched in, the built-in interrupt handler handles the interrupt as determined by certain mode bytes. When writing your serial interrupt handler, refer to Figures 11-37 through 11-39 and to the Synertek 6551 ACIA specification. As shown in Chapter 11, the ACIAs have the following connections: Port 1 DSR line (pin 17) connected to the EXTINT line on the external disk port; connected to +5 volts through a 3.35 ohm resistor on the Apple He Plus. DCD line (pin 16) connected to pin 5 of port 1 connector. Port 2 DSR line connected to keyboard strobe; goes high when a key is pressed. DCD line connected to pin 5 of port 2 connector. The ACIA registers have the following addresses: Port 1 Port 2 Data register $C098 Data register $C0A8 Status register $C099 Status register $C0A9 Command register SC09A Command register SCOAA Control register $C09B Control register $C0AB 106 Apple lie Technical Reference Chapter 4 Introduction to Apple He I/O This chapter is an introduction to the built-in I/O capabilities of the Apple lie and Apple He Plus computers. This chapter oudines • standard I/O links and their functions • I/O firmware protocols • dedicated memory storage locations • direct I/O • 107 The standard I/O links You can use some of the routines in the Apple He family's firmware for your own programs. Ibis can save you both program space and the time and effort of writing all your own I/O routines. There are two levels of firmware subroutines used for I/O; one level is the I/O subroutines, the other level is the standard input/output routines. When your program makes a call to an I/O subroutine, the called routine checks a standard location in memory for the address of the input or output routine to which it should pass control. The address to which the 1/0 subroutine passes control is called a vector, and the standard locations in memory that contain the vectors used by I/O subroutines are called the I/O links. To use an 1/0 subroutine, your program must perform a JSR instruction to the routine's address (its entry point). The called routine then performs an indirect jump instruction to the address pointed to by the standard I/O link and begins executing. When the routine is finished, it executes an RTS instruction and control is returned to your program at the first instruction following the original JSR instruction. • Note: JSR means fump to SubRoutine. It is a machine-language statement that causes control to be turned over to the routine loaded at a specified address (called the jump address). An Indirect jump jumps to a vector pointing it to the start of the routine. RTS means Return To Statement. It is a machine-language statement that causes the routine to end and control to be passed back to the application program or operating system that initiated the call at the statement immediatly following the call. In an Apple lie or Apple lie Plus running without an operating system, each I/O link normally contains the address of the standard input or output routine. The reason to use this indirect approach instead of calling the standard input/output routines directly is that an operating system might substitute its own input or output routines for the standard ones in firmware. For example, an operating system might redirect output to go to a file rather than to the screen. If your program calls the standard input/output routines in ROM rather than the I/O subroutines, it bypasses the operating system and may not work properly with new versions of the operating system or firmware. 108 Apple He Technical Reference • Note.- Not all operating systems use the standard I/O links. For example, Apple Pascal does not use them. The standard I/O links are at locations $36 and $38. The link at location $36 is called CWfxharacter output switch). Individually, location $36 is called CW/,(CSW low) and location $37 is called CSWH(CSW high). The CSW link holds the starting address of the subroutine the computer is currently using for single-character output. The link at location $38 is called AW(keyboard input switch). Individually, location $38 is called /sT5U/Z(KSW low) and location $39 is calledtfSWW(KSWhigh). This link holds the starting address of the routine currently being used for single-character input. When you issue either a PR#« from BASIC or an n Control-P from the System Monitor, the Apple lie or Apple lie Plus changes the value in the CSW link to the first address in the ROM space allocated to port n. That address is SCnOO. The next time a character is output using the standard output routine, control is transferred to the firmware starting at SCnOO. When it has finished, the firmware executes an RTS instruction to return control to the calling program. Sometimes the firmware at $CnOO changes both input and output links; for example, when you issue a PR#3 to invoke the enhanced video firmware, the routine that starts at $C300 changes both the input and output links to point to enhanced video firmware routines. Enhanced video firmware is described in the section "Enhanced Video Firmware" in Chapter 6. When you issue an 1N#M command from BASIC or an n Control-K from the Monitor, the Apple lie or Apple lie Plus changes the value in the KSW link to the first address in the ROM space allocated to port n; that is, to $CnOO. The IN#n command and n Control-K command work in a similar fashion to the output-link commands: the next call for character input is transferred to the firmware starting at SCnOO. Notice that not all ports can be used for I/O. The firmware starting at SC600, the 5.25-inch disk drive port, for example, causes the computer to attempt to restart from a disk in the first 5.25-inch disk drive. When a disk operating system (DOS or ProDOS) is running, one or both of the standard I/O links hold addresses of the disk operating system's input and output routines. The operating system has internal locations that hold the addresses of the currently active character input and output routines. CHAPTER 4 Introduction to Apple lie I/O 109 • Warning If a program that is running with DOS or ProDOS changes the values in the standard I/O links, either directly or via IN# and PR# commands, the operating system may be disconnected from the system. To avoid this problem when programming in BASIC, you should always issue an empty PRINT statement followed by a PRINT statement containing Control-D and the IN* or PR* command. Applesoft passes on to the operating system any command following a carriage return-Control-D. • A DOS 3.3 After changing either CSW or KSW, your assembly-language programs running under DOS 3.3 should call the subroutine at location $03EA. This subroutine transfers the link address to a location inside the operating system and then restores the operating system link address in the standard link location, A The I/O links contain the addresses of the Keyln and COutl routines if the enhanced video firmware is off (when the display shows a flashing checkerboard cursor), and of the C3KeyIn and C3COutl routines if the enhanced video firmware is on (when the display shows an inverse solid cursor). All of these I/O routines are described in this chapter. The enhanced video firmware is described in Chapter 6. Standard input routines The Apple lie family's firmware includes two different subroutines that your program can call in order to read data from the keyboard: RdKey (read key) and GetLn (get line). RdKey calls the current character input routine (that is, the one whose address is stored at KSW). This routine is normally Keyln or C3KeyIn, either of which accepts one character from the keyboard. GetLn repeatedly calls the current character input routine to allow your program to get a sequence of characters terminated with a carriage return. Thus GetLn allows line-oriented input using the current input routine. GetLn also provides some on- screen editing features, as described in the section "Editing With GetLn," later in this chapter. 110 Apple He Technical Reference RdKey subroutine A program can get a character from the keyboard by making a subroutine call to RdKey at memory location $FD0C. RdKey passes control via the input link KSW to the current input routine. RdKey displays a cursor at the current cursor position, which is immediately to the right of whatever character you last sent to the display (normally by using the COut routine, described later in this chapter). GetLn Subroutine Programs often need strings of characters as input. While you could call RdKey repeatedly to get several characters from the keyboard, there is an easier way to do it. The routine that you can use in this case is named GetLn, and it starts at location $FD6A. Using repeated calls to RdKey, GetLn obtains characters from the current input routine and puts them into the input buffer located in the memory page from $0200 to $02FF. GetLn also provides some basic on-screen editing and control features. The first thing GetLn does when you call it is to display a prompt. The prompt indicates to the user that the program is waiting for input. Different programs use different prompt characters, helping to remind the user which program is requesting the input. Table 4-1 shows the prompt characters used by standard programs on the Apple lie family. GetLn uses the character stored at memory location $33 as the prompt character. In an assembly-language program, you can change the prompt to any character you wish. In BASIC, changing the prompt character has no effect because both BASIC interpreters and the Monitor restore it each time they request input from the user. Note: Applesoft uses GetLnl ($FD6F) when a program is executing. GetLnl does not print a prompt. CHAPTER A Introduction to Apple He I/O 111 Table 4-1 Prompt characters Prompt character Program requesting Input ? User's BASIC program (INPUT statement) ] Applesoft BASIC (Appendix C) > Integer BASIC (Appendix C) * Firmware Monitor (Chapter 10) As the user types each character, GetLn sends the character to the current output routine, which displays it al the current cursor position and then advances the cursor to indicate the next character position. Control characters echoed by GetLn are not executed. GetLn stores the characters in its buffer, which starts at memory location $0200. GetLn uses the X register to index the buffer. GetLn continues to accept and display characters until the user presses Return (the user can also press Control-X to cancel the line). Then it clears the remainder of the line the cursor is on, stores the carriage- return code to mark the end of the buffer, places the cursor at the beginning of the next line, and returns to the routine that called it. The maximum line length that GetLn can handle is 255 characters. If the user types more than this, GetLn sends a backslash ( \ ) and a carriage return to the display, cancels the line it has accepted so far, and starts over. To warn the user that the line is getting full, GetLn sounds a bell (tone) at every keypress after the 248th. • Note: The Applesoft interpreter accepts only 239 characters. Escape sequences with GetLn GetLn has many special functions that you invoke by typing escape sequences on the keyboard An escape sequence is sent by pressing Esc (Escape), releasing it, and then pressing some other key, as shown in Table 4-2. A Important Be sure to release Esc right away. If you hold it too long, the auto-repeat mechanism begins, which may cancel the escape sequence, A 112 Apple lie Technical Reference Table 4-2 Escape sequences with GetLn Escape code Function Esc Clears the window and homes the cursor (places it in the upper-left comer of the screen); exits from escape mode Esc A or Esc a Moves the cursor right one line; exits from escape mode Esc B or Esc b Moves the cursor left one line; exits from escape mode Esc C or Esc c Moves the cursor down one line; exits from escape mode Esc D or Esc d Moves the cursor up one line; exits from escape mode Esc E or Esc e Clears to the end of the line; exits from escape mode Esc F or Esc f Clears to the bottom of the window; exits from escape mode Esc I or Esc tor Esc Up Arrow Moves the cursor up one line; remains in escape mode Esc J or Esc jor Esc Left Arrow Moves the cursor left one space; remains in escape mode' Esc K or Esc k or Esc Right Arrow Moves the cursor right one space; remains in escape mode* Esc M or Esc m or Esc Down Arrow Moves the cursor down one line; remains in escape mode' Esc 4 Switches to 40-column mode; sets links to C3KeyIn and C3COutl; restores normal window size (Table 4-5); exits from escape modef Esc 8 Switches to 80-column mode; sets links to C3KeyIn and C3COutl; restores normal window size (Table 4-5); exits from escape modef Esc Control-D Disables control characters; only carriage return, line feed, bell, and backspace have an effect when printed Esc Control-E Reactivates control characters Esc Control-Q Deactivates the enhanced video firmware; sets links to Keyln and COutl; restores normal window size (fable 4-5); exits from escape modef • Cursor-control key: see text. f This code functions only when the enhanced videofirmwareis active. In escape mode, you can keep using the arrow keys and the cursor movement keys I, J, K, and M without pressing Esc again. This enables you to perform repeated cursor moves by holding down the appropriate key. CHAPTER 4 Introduction to Apple He I/O 113 When GetLn is in escape mode, it displays an inverse plus sign as the cursor. You leave escape mode by typing any key other than a cursor movement key. • Note: The escape sequences that use the arrow keys are the standard cursor movement keys on the Apple He family. The escape sequences that use I, J, K, and M are the standard cursor movement keys on the Apple II and Apple II Plus, and are present on the Apple He family for compatibility. Escape sequences can be used in the middle of an input line to change the appearance of the screen. They have no effect on the input line. Editing with GetLn The GetLn subroutine provides the standard on-screen editing features used by the BASIC interpreters and the Monitor. Any program that uses GetLn for reading the keyboard has these features. Cancel line Any time you are typing a line, pressing Control-X causes GetLn to cancel the line. GetLn displays a backslash (\) and issues a carriage return, then displays the prompt and waits for you to type a new line. GetLn takes the same action when you type more than 255 characters, as described earlier. Backspace When you press Left Arrow (or Control-H), GetLn moves its buffer pointer back one space, effectively deleting the last character in its buffer. It also sends a backspace character to routine COut, which moves the cursor back one space. If you type another character now, it replaces the character you backspaced over, both on the display and in the line buffer. Each time you press Left Arrow, it moves the cursor left and deletes another character, until you are back at the beginning of the line. If you then press Left Arrow one more time, you have effectively canceled the line, and GetLn issues a carriage return and displays the prompt. The cursor moves even if the deleted character is an invisible control character. Thus it is possible for screen alignment and buffer alignment to be different. 114 Apple He Technical Reference Retype Right Arrow (or Control-U) has a function that is complementary to the backspace function. When you press Right Arrow, GetLn picks up the character under the cursor just as if it had been typed on the keyboard. You can use this procedure to pick up characters that you just deleted by backspacing across them. You can use the backspace and retype functions with the cursor-motion functions to edit data on the display. The Keyln and C3KeyIn input routines Keyln is the standard input routine that is used when the enhanced video firmware (described in Chapter 6) is not in use. C3KeyIn is the standard input routine that is used when the enhanced video firmware is active. When called (usually by RdKey or by GetLn), either routine displays a cursor, waits until the user presses a key, then inserts the ASCII code of the key just pressed in the A register (accumulator) and returns to the calling program. Keyln displays a cursor by alternately storing a checkerboard block in the memory location used for the cursor character, storing the original character, then storing the checkerboard again. C3KeyIn places a block cursor on the screen by inverting (swapping black for white) the character at the cursor position. Keyln and C3KeyIn also generate a random number. While it is waiting for the user to press a key, the input routine repeatedly increments the 16-bit number in memory locations $4E and $4F. This number keeps increasing from 0 to $FFFF (65535), then starts over again at 0. The value of this number changes so rapidly that it is very difficult to predict what it will be after a key is pressed. A program that reads from the keyboard can use this value as a random number or as a seed for a pseudo-random number routine. Standard output routines The output subroutine provided for your use is named COut (character output). COut calls the current character output routine (that is, the one whose address is stored at CSW). This routine is normally COutl or C3COutl, either of which sends one character to the display, advances the cursor position, and scrolls the display when necessary. COutl and C3COutl restrict their use of the display to an active area called the text window, described later in this chapter. r CHAPTER 4 Introduction to Apple He I/O 115 *v COut subroutine When your program places a character in the A register and makes a subroutine call to COut at memory location $FDED, COut passes control via the output link CSW to the current output routine. If the output routine is COutl or C3COutl, and the A register contains an uppercase or lowercase letter, a number, or a special character, the routine displays the character on the screen. If the A register contains a control character, COutl or C3COutl either performs one of the special functions described below or ignores the character. Each lime you send a displayable character to COutl or C3COull, it displays the character at the current cursor position, replacing whatever was there, and then advances the cursor position one space to the right. If the cursor position is already at the right edge of the window, COutl or C3COutl moves it to the leftmost position on the next line down. If this would move the cursor position past the end of the last line in the window, COutl or C3COutl scrolls the display up one line and sets the cursor position at the left end of the new bottom line. The cursor position is controlled by the values in memory locations $24 and $25. These locations are named CH, for cursor horizontal, and CV, for cursor vertical. COutl and C3COutl do not display a cursor, but the input routines (such as Keyln or C3KeyIn) do, and they use this cursor position. However, changing CV directly does not change the cursor's vertical position until the next carriage return or until reaching the end of the current line causes a call to VTab (for setting the base address within windows). If some other routine displays a cursor, it does not necessarily put it in the cursor position used by COutl or C3COutl. A Important When the enhanced video firmware is active, the value of CH is kept at 0 and the true horizontal position is stored at $057B. When the enhance video firmware is active, use S057B instead of CH. A Control characters with COutl COutl does not display control characters. Instead, the control characters listed in Table 4-3 are used to initiate some action by the firmware. Other control characters are ignored. Most of the functions listed here can also be invoked from the keyboard, either by typing the control character listed or by using the one of the escape sequences shown in Table 4-2. The stop-list function, described separately, can only be invoked from the keyboard. 116 Apple He Technical Reference Table 4-3 Control characters with COutl Control character ASCII name Apple lie name Action taken by COutl Control-G BEL Bell Produces a 1000 Hz tone for 0.1 second Control-H BS Backspace Moves cursor position one space to the left; from left edge of window, moves to right end of line above Control-J LF Line feed Moves cursor position down to next line in window; scrolls if needed Control-M CR Return Moves cursor position to left end of next line in window; scrolls if needed Control-S DC3 Stop-list Stops listing characters on the display until another key is pressed! t Only works from the keyboard. Control characters with C3COutl When the enhanced video firmware is active, COut calls C3COutl instead of COutl for character output. C3COutl does not display control characters, but you can use certain control characters to control some functions. All other control characters are ignored. The control characters listed in Table 4-4 are used to initiate some action by the firmware. Except for the stop- list function (Control-S) you can send control characters to C3COutl either from a program or from the keyboard. The stop-list function can only be invoked from the keyboard. Most of the functions listed here can also be performed by using one of the escape sequences shown in Table 4-2. CHAPTER 4 Introduction to Apple He I/O 117 Table 4 4 Control characters with C3COutl Control character ASCII name Apple Tic name Action taken by C3COutl Control-G BEL Bell Produces a 1000-Hz tone for 0.1 second Control-H BS Backspace Moves cursor position one space to the left; from left edge of window, moves to right end of line above Control-J LF Line feed Moves cursor position down to next line in window; scrolls if needed Control-K VT dear EOS Clears from cursor position to the end of the screen* Control-L FF Home and clear Moves cursor position to upper-left corner of window and clears window' Control-M CR Return Moves cursor position to left end of next line in window; scrolls if needed Control-N 30 Normal Sets display format normal* Control-0 SI Inverse Sets display format inverse' Control-Q DC1 40-column Sets display to 40-column* Control-R DC2 80-column Sets display to 80-column* Control-S DC3 Stop-list Stops listing characters on the display until another key is pressed! Control-U NAK Quit Turns off enhanced video firmware* Control-V SYN Scroll Scrolls the display down one line, leaving the cursor in the current position* Control-W ETB Scroll-up Scrolls the display up one line, leaving the cursor in the current position* Control-X CAN Disable MouseText Disables MouseText character display; uses inverse uppercase* Control-Y EM Home Moves cursor position to upper-left corner of window (but doesn't clear)* Control-Z SUB Clear line Clears the line die cursor position is on* Control-! ESC Enable MouseText Maps inverse uppercase characters to MouseText characters' Controls FS Fwd. space Moves cursor position one space to the right; from right edge of window, moves it to left end of line below' Conlrol- GS dearEOL Clears from the current cursor position to the end of the line (that is, to the right edge of the window)* Control- US Up Moves cursor up a line, no scroll* • Doesn't work from the keyboard. t Works only from the keyboard. 118 Apple He Technical Reference The stop-list feature You can stop the computer from updating its display (if it is using either COutl or C3C0utl) by pressing Control-S. Whenever COutl or C3COutl gets a carriage return from the program, it checks the keyboard for a Control-S. If a Control-S has been pressed, COutl or C3COutl stops and waits for another key to be pressed before resuming. The character code of the key that is pressed is ignored unless it is Control-C, which is passed to the program. This last feature lets you exit BASIC programs from stop-list mode. The text window The active portion of the display is called the text window. After you start up the computer or perform a reset, the entire display is the text window. COutl or C3COutl puts characters only into the window; when it reaches the end of the last line in the window, it scrolls only the contents of the window. You can restrict video activity to any rectangular portion of the display by changing the current text window. Your programs can thus control the placement of text in the display and protect other portions of the screen from being written over by new text. To do this, store the appropriate values into four locations in memory to set the top, bottom, left margin, and width of the text window. The following memory locations control the text window: • The left margin is stored in memory location $20. This number is normally 0, the number of the leftmost column in the display. In a 40-column display, the maximum value for this number is 39 (hexadecimal $27); in an 80column display, the maximum value is 79 (hexadecimal $4F). • The width of the text window is stored in memory location $21. For a 40-column display, this value is normally 40 (hexadecimal $28); for an 80column display, it is normally 80 (hexadecimal $50). • The position of the top line of the text window is stored in memory location $22. This is normally 0, the topmost line in the display. Its maximum value is 23 (hexadecimal $17). • The position of the bottom line of the screen plus 1 is stored in memory location $23. It is normally 24 (hexadecimal $18) for the bottom line of the display. Its minimum value is 1. A Important Pascal does not use this method of supporting window widths, A r CHAPTER 4 Introduction to Apple He I/O 119 A Warning Be careful not to let the sum of the window width and the leftmost position in the window exceed the width of the display you are using (40 or 80 columns). If this happens, COutl or C3COutl may put characters into memory locations outside the display page, possibly destroying programs or data, A Table 4-5 summarizes the memory locations and the possible values for the text window parameters. • Table 4-5 Text window memory locations Minimum Normal values Maximum values Window Location value 40-col. eo-wi, 40-col. gO-col. parameter Dec Hex Dec Hex Dec Hex Dec Hex Dec Hex Dec Hex Left edge 32 $20 00 $00 00 $00 00 $00 39 $27 79 $4F Width 33 $21 00 $00 40 $28 80 $50 40 $28 80 $50 Top edge 34 $22 00 $00 00 $00 00 $00 23 $17 23 $17 Bottom edge 35 $23 01 $01 24 $18 24 $18 24 $18 24 $18 Normal, inverse, and flashing text The way that the Apple He family displays characters is affected by two things: the value that is stored in the inverse flag (zero-page location $32), and whether the enhanced video firmware (described in Chapter 6) is off or on. The inverse flag's influence is discussed in the next two subsections. If the enhanced video firmware is off, the Apple He family displays what is called the primary character set; if the enhanced video firmware is on, the Apple He family displays what is called the alternate character set. 120 Apple He Technical Reference The primary character set includes normal (light on dark), inverse (dark on light), and flashing (alternating normal and inverse) characters. Lowercase inverse characters are not included in the primary character set. The alternate character set includes normal and inverse characters (including lowercase inverse), and a set of graphic characters called MouseText. Flashing characters are not included in the alternate character set. These character sets are described in more detail in the section "Text Character Sets," in Chapter 6. If you want your program to display a character, it should first load the character to be displayed in the A register, and then call the character-output subroutine COut. For example, to display the character corresponding to $C8, you can use something like this: LDA #$C8 JSR COut Primary-character-set display The primary character set is displayed by COutl, which operates only when the enhanced video firmware is off. The primary character set includes text in normal, inverse, or flashing format, but not inverse or flashing lowercase text. If the value of the character sent to COutl is greater than or equal to $A0, COutl performs a logical AND operation on the value of the character with the value of the inverse flag (al location $32), and the result is displayed. (If you're curious about which ASCII character is being sent, subtract $80 from the value being sent to COutl.) You can use the following inverse flag values: • $FF (decimal 255) produces the normal character format. • $3F (decimal 63) produces the inverse character format. • $7F (decimal 127) produces the flashing character format. A Important To avoid unusual character display results, use only the three values $3F, $7F, and $FF. A COutl interprets character values from $80 through $9F as control characters and tries to execute them. Character values from $00 through $7F are all interpreted as display characters, not control characters. CHAPTER 4- Introduction to Apple lie I/O 121 Alternate-character-set display The alternate character set includes normal and inverse format characters and the MouseText graphic characters. You should use C3COutl, the standard output link when the enhanced video firmware is active, to display the alternate character set. Here are the rules for using the alternate character set: • Control characters are not displayed. Characters sent to C3COutl are interpreted as control characters if they are in the range $00 through $lFor $80 through $9F. • Characters in the range $20 through $7F and $A0 through $FF are displayed. • If inverse flag (location $32) bit 7 is 1, the character is normal. • If inverse flag bit 7 is 0, the character is inverse. • If MouseText is off, characters $40 through $5F are remapped to the range $00 through $1F and are displayed as uppercase inverse characters. • If MouseText is on, character values $40 through $5F are left unchanged, and the characters are displayed as MouseText. See the section "MouseText," in Chapter 6, for more information about MouseText. Port I/O The Apple He and Apple He Plus are members of the Apple II family of computers; however, unlike the Apple II, II Plus, He, and lies, the Apple lie and Apple lie Plus do not have peripheral connector slots. In place of these, they have ports—the built-in firmware and hardware equivalent of the expansion cards installed in slots in the other Apple II computers. 122 Apple He Technical Reference Standard port entry points To maintain compatibility with existing software and its protocols, each port's I/O firmware has the same standard entry point ($CnOO) as its equivalent slot in another Apple II would have. Tables 4-6 and 4-7 show these equivalents for the various versions of the Apple He, as well as listing the chapter where each port is described. Connectors and hardware descriptions of ports are given in Chapter 11. Executing a PR#«or IN#n command from Applesoft changes the standard output or input links, respectively, so that the next output or input through the standard I/O links causes a jump to the firmware entry point at address $CnOO. See the earlier section "The Standard I/O Links," earlier in this chapter, for more information on the standard I/O links. • Table 4-6 Original and UniDisk 3-5 Apple He port characteristics Port Entry point Port connector Use Chapter 1 $C100 Serial port 1 Printers 7 2 SC200 Serial port 2 Communication 7 3 $C300 Video connectors Enhanced video firmware 6 4 $C400 Mouse Mouse 9 5 $C500 Intelligent disk port devices External 3.5-inch drives' 8 6 $0600 Disk drives Built-in and external drives 8 7 $C700 No device Reserved UniDisk 3-5 Apple Ik only CHAPTER 4 Introduction to Apple lie I/O 123 • Table 4-7 Memory expansion Apple lie and Apple lie Plus port characteristics Port Entry point Port connector Use Chapter 1 $C100 Serial port 1 Printers 7 2 $C200 Serial port 2* Communication 7 3 $C300 Video connectors Enhanced video firmware 6 4 $C400 Memory expansion card Memory expansion card 8 5 SC500 3.5 inch disk drives Built-in and external 3.5-inch drives 8 6 $0500 5.25 inch disk drives Built-in and external 5.25-inch drives 8 7 $C700 Mouse Mouse 9 • Also supports second and third external 3.5-inch drives. Firmware protocol The Apple lie family supports a standard firmware protocol that, in addition to the standard link address, provides a table of device identification and entry points to standard and optional firmware subroutines. The protocol is equivalent to the Pascal 1.1 firmware protocol in use on other Apple II computers, and is outlined in Table 4-8. In Table 4-8, n is the port number. 124 Apple He Technical Reference Table 4-8 Firmware protocol locations Address Value Description $Cn05 $38 Pascal firmware card/port identifier. $Cn07 $18 Pascal firmware card/port identifier. SCnOB $01 Generic signature byte of a firmware card/port. SCnOC $ci Device signature byte: i is an identifier (not necessarily unique). c = device class (not all used in the Apple lie family): $00 reserved $01 printer $02 hand control or other X-Y device $03 serial or parallel I/O card/port $04 modem $05 sou nd or speech device $06 clock $07 mass-storage device $08 80-column card/port $09 network or bus interface $0A special purpose (none of the above) $0B-0F reserved SCnOD ii $Cnii is the initialization entry address (PInit). SCnOE rr $Cnrr is the read routine entry address (PRead) (returns character read in A register). $Cn0F w $Cnww is the write routine entry address (PWrite) (enters with character to write in A register). $Cnl0 ss $Cnss is the status routine entry address (PStatus) (enters with request code in A register: 0 to ask "Are you ready to accept output'" or 1 to ask "Do you have input ready?"). $Cnll $00 If additional address bytes follow; nonzero if not. Each table begins with identification bytes ($Cn05 through $Cn0C). Then, starting with address $Cn0D, each byte in the table represents the low-order byte of the entry-point address of a firmware routine. The high-order byte of each address is always $Cn, where n is the port number. Your program uses these byte values to construct its own jump table for subroutine calls to the ports. All port routines require, on entry, that the X register contain $Cn and that the Y register contain $n0. CHAPTER 4 Introduction to Apple He I/O 125 All routines, on exit, return an error code in the X register (0 means no error occurred; 3 means the request was invalid). The carry bit in the program status register usually contains a reply to a request code (0 means no; 1 means yes). All the ports in the Apple lie family except the disk port conform to this protocol. The disk port is described in Chapter 8. Port I/O space By a convention used in other Apple II-series machines, each port or slot has exclusive use of 16 memory locations set aside for data input and output. The addresses of these locations are of the form $C080 + $n0, where n is the port or slot number. Table 4-9 lists the port I/O space used in the Apple lie family. See the section "The Hardware Page," in Appendix B, for the assignments of specific addresses. • Table 4-9 Port I/O locations Port Locations 1 $C090-$C09F 2 $C0AO-$COAF 5 $C0DO4CODF 6 $C0E0-$O0EF Port ROM space In the Apple II and He, one 256-byte page of address space is allocated to each slot. Ibis space is used for read- only memory (ROM or PROM on the interface card) with driver programs that control the operation of input/output devices, as outlined in Table 4-8. In the Apple Be family, this space is dedicated to port firmware. However, I/O ROM space in the Apple lie family is used as efficiently as possible, and there is no/a strict correspondence between firmware for port « and the $Cn00 space, except that the entry point for port n is always at $Cn00. 126 Apple He Technical Reference Expansion ROM space The 2 KB memory space from $C800 to $CFFF in the Apple Ilc-family main ROM contains the enhanced video firmware, port 3, and subroutines used to transfer data between locations in memory. The Apple lie family, unlike the Apple II, Apple II Plus, or Apple lie, always has this space switched in; that is, when the system switches between ROM and RAM, the $C800 through SCFFF address space remains assigned to ROM. Port screen hole RAM space There are 128 bytes of memory (64 in main memory, 64 in auxiliary memory) allocated to the ports, 8 bytes per port, as shown in Table 4-10. These bytes are reserved for use by the system, except as described in Chapters 5 through 9. • Table 4-10 Port screen hole memory locations t Base address 1 2 3 Ports 4 5 6 7 $0478 SCM79 $047A $047B $047C $047D $047E $047F $04F8 $04F9 $04FA $04FB $04FC $04FD $04FE $04FF $0578 $0579 $057A $057B $057C $057D $057E $057F $05F8 $05F9 $05FA $05FB $05FC $05FD $05FE $05FF $0678 $0679 $067A $067B $067C $067D $067E $067F $06F8 $06F9 $06FA $06FB $06FC $06FD $06FE $06FF $0778 $0779 $077A $077B $077C $0T7D $077E $077F $07F8 $07F9 $07FA $07FB $07FC $07FD $07FE $07FF These addresses are unused bytes in the RAM reserved for text and Lo-Res graphics displays, and hence they are called screen holes. These particular locations are not displayed on the screen and their contents are not changed by the built-in output routines. In other words, they are used by the output routines, but they are not part of the video display. CHAPTER 4 Introduction to Apple He I/O 127 • Warning All the screen holes in auxiliary memory, and many of them in main memory, are reserved for special use by Apple Ilc-family firmware—for example, to store initialization information. Do not use any locations marked reserved in this manual, A The way that port firmware uses these RAM locations and their addresses is covered in Chapters 5 through 9. Interrupts Interrupts are a way to more efficiently use the hardware in a computer. Interrupt support built into the Apple He family's firmware is described briefly in this section. For a complete description of interrupts in the Apple Ilc-family computers, see Chapter 3. When the IRQ line on the 65C02 microprocessor is activated, the 65C02 transfers program control through the vector in locations $FFFE through $FFFF of ROM or whichever bank of RAM is switched in. If ROM is switched in, this vector is the address of the Monitor's interrupt handler, which determines whether the request is due to an interrupt that should be handled internally. If so, the Monitor handles it and then returns control to the interrupted program. If the interrupt is due to a BRK ($00) instruction, control is transferred through the BRK vector ($03F0-$03F1). Otherwise, control is transferred through the IRQ vector ($03FE-$03FF). 128 Apple He Technical Reference Chapter 5 Keyboard and Speaker This chapter describes how your program can use the Apple lie keyboard and the speaker. Notice that the keyboard used in the Apple lie Plus computer differs from older Apple lie keyboards only in the layout and labeling of some of the keys; the Apple lie Plus keyboard functions in exacdy the same way as older keyboards. See Chapter 11 for physical descriptions of the keyboards used in the Apple He and Apple He Plus computers. • 129 Keyboard input Table 5-1 describes the characteristics of the keyboard that relate to programming. You won't have to write routines to read the keyboard from your assembly-language programs since the Apple lie family System Monitor provides keyboard support through the three standard input routines described in Chapter 4—RdKey, Keyln, and GetLn. You can do all your keyboard handling directly in your programs if you want to, but it's nice to know that you're not forced to. Reading the keyboard The keyboard encoder and ROM (see Chapter 11) can generate all 128 ASCII codes, so all the special character codes in the ASCII character set are available from the keyboard. Your machine-language programs can call RdKey to get characters from the keyboard. RdKey reads characters a byte at a time from the keyboard data location ($COO0). Here is how your programs should go about reading the keyboard 1. Test bit 7 of address $C000 to see if a key has been pressed. Bit 7 is the keyboard strobe bit. 2 When bit 7 goes to a 1, you know that the low-order seven bits of $C0OO are a valid character. 3. Clear the keyboard strobe (bit 7) at $C000 by reading or writing anything to address $C010. $C010 has another function besides clearing the keyboard strobe: its high bit is a 1 while a key is pressed (except Command (Open Apple), Option (Solid Apple), Control, Shift, Caps Lock, and Reset). Bit 7 al this location is therefore called any-key-down. You could use this to let a program do something useful other than just waiting for the next key to be pressed. (People are generally a lot slower than the Apple Ilc-family computers.) Check $C010 occasionally to see if something should be done. A Important If your program needs to read both the any-key-down flag and the keyboard strobe, it must read the strobe bit first. Any time you read the any-key-down bit at $C010, you also clear the keyboard strobe bit at SCOOO. A 130 Apple He Technical Reference Table 5-1 Keyboard input characteristics Port number None Commands Keyboard is always on, in the sense that any keypress generates a KSTRB signal. Initial characteristics Reset routine clears the keyboard strobe and sets the keyboard as the standard input device (that is, sets KSW to point to RdKey). Hardware locations $C000 Keyboard data and strobe $C010 Any-key-down flag and clear-strobe switch $C060 40/80-column switch status on bit 7; 1 = 40-column display (switch down)* $0061 Command key status on bit 7; 1 = pressed (also game input switch 0 and first mouse button status!) $C062 Option key status on bit 7; 1 = pressed Monitor firmware routines Location Name Description SFD6A GetLn Gets an input line with prompt $FD67 GetLnZ Gets an input line with preceding carriage return $FD6F GetLnl Gets an input line, but with no preceding prompt $FD1B Keyln The keyboard input subroutine $FD35 RdChar Gets an input character or escape code $FD0C RdKey The standard character input subroutine Use of other pages Page 2 The standard character string input buffer (see GetLn description) • The Apple He Plus does not have a 40/80 column switch. t Game input soft switches are listed and described in the section "Game Input," in Chapter 9. After your program has cleared the keyboard strobe, the strobe remains low until another key is pressed. Table 5-2 shows the ASCII codes generated by all the keys on the Apple He keyboard. The Apple lie Plus keyboard generates the same key codes as the older Apple lie keyboards. CHAPTER 5 Keyboard and Speaker 131 • Note: If the strobe bit is set, the character values that your program sees will be equal to the values given in Table 5-2 plus $80. Table 5-2 Keys and ASCII codes Key alone + !Control + Shift + Both Key Code Char Code Char Code Char Code Char Delete IV DEL 7F DEL 7F DEL 7F DEL Left Arrow 08 BS C8 BS 03 BS 03 BS Tab 09 HT 09 HT 09 HT C9 HT Down Arrow 0A LF 0A LF 0A LF 0A LF Up Arrow OB VT 0B VT 0B VT 0B VT Return 0D CR 0D CR 0D CR 0D CR Right Arrow 15 NAK 15 NAK 15 NAK 15 NAK . Esc IB ESC IB ESC IB ESC IB ESC Space 20 SP 20 SP 20 SP 20 SP •» 27 i 27 i 22 >i 22 H ,< 2C i 2C i 3C < 3C < -_ 2D - IF US 5F IF US .> 2E , 2E , 3E > 3E > /? 2F / 2F / 3F 7 3F •> 0) 30 0 30 0 29 ) 29 ) 1! 31 1 31 1 21 ! 21 j 29 52 2 00 NUL 40 @ 00 NUL 3# 33 3 33 3 23 # 23 # 4$ 31 4 34 4 24 $ 24 $ 5% 35 5 35 5 25 % 25 % 6A 36 6 IE RS 5E A IE RS 7& 37 7 37 7 26 & 26 & 8* 38 8 38 8 2A 1 2A • 9( 39 9 39 9 28 ( 28 ( j• 3B ! 3B i 3A 3A : =+ 3D = 3D = 2B + 2B + [{ 5B i IB ESC 7B { IB ESC \l 5C \ IC FS 7C 1 IC FS 1} 5D i ID GS 7D } ID GS l~ (O i 60 i 7E - 7E - 132 Apple lie Technical Reference Table 5-2 Keys and ASCII codes (continued) Key alone + Control + shift + Both Key Code Char Code Char Code Char Code Char A 61 a 01 SOH 41 A 01 SOH B 62 1) 02 STX 42 B 02 STX C 63 c 03 ETX 43 C 03 ETX D 64 d 04 EOT 44 D 04 EOT E 65 e 05 ENQ 45 E 05 ENQ F 66 f 06 ACK 46 F 06 ACK G 67 B 07 BEL 47 G 07 BEL 11 68 h 08 BS 48 H 08 BS I 69 i 09 HT 49 I 09 HT J 6A i 0A LF 4A J 0A LF K 6B k 0B VT 4B K 0B VT L 6C 1 0C FF C L OC FF M 6D m 0D CH 4D M 0D CR N 6E n 0E SO 4E N 0E SO 0 6F 0 OF SI 4F O OF SI P 70 P 10 DLE 50 P 10 DLE Q 71 q 11 DC1 51 Q 11 DC1 R 72 r 12 DC2 52 R 12 DC2 S 73 s 13 DC3 53 S 13 DC3 T 74 t 14 DC4 54 T 14 DC4 U 75 u 15 NAK 55 U 15 NAK V 76 v 16 SYN 56 V 16 SYN w 77 w 17 ETB 57 W 17 ETB X 78 X 18 CAN 58 X 18 CAN Y 79 y 19 EM 59 Y 19 EM Z 7A z 1A SUB 5A Z 1A SUB There are three keys that do not generate ASCII codes themselves, but alter the characters produced by other keys. These modifier keys are Control, Shift, and Caps Lock. You can also use the Command (Open Apple) and Option (Solid Apple) keys as character modifier keys while handling keyboard input. You can read Command at $C06l and Option at $C062. Another key that doesn't generate a code is Reset, located at the upper-left corner of the keyboard; it is connected directly to the microprocessor RESET line. Pressing Control-Reset causes a warm reset. Pressing Command -Control-Reset causes a forced cold reset. The reset procedures are described in Chapter 4. CHAPTER 5 Keyboard and Speaker 133 Monitor firmware support for keyboard input Chapter 4 describes the three standard Monitor input routines serving the keyboard: GetLn, RdKey, and Keyln. This section discusses the three other Monitor routines that serve the keyboard. GetLnZ GelLnZ (at address $FD67) is an alternate entry point for GetLn that first sends a carriage return to the standard output, then continues into GetLn. GetLnl GetLnl (at address $FD6F) is an alternate entry point for GetLn that does not issue a prompt before it accepts the input line. However, if the user cancels the input line with too many backspaces or with Conlrol-X, then GetLnl issues the prompt stored at location $33 when it gets another line. RdChar RdChar (at address $FD35) is a subroutine that gets characters from the standard input subroutine, and also interprets the escape codes listed in Chapter 4. If the enhanced video firmware is active, Right Arrow (Control-U) reads a character from the screen as if it were typed from the keyboard. This is a function of the Monitor's built-in editing capability described in Chapter 4. The enhanced videofirmwareis discussed in Chapter 6. 134 Apple lie Technical Reference Speaker output The Apple He and Apple lie Plus have a small speaker mounted near the front of the bottom plate of the case. The speaker is connected to a soft switch that toggles; that is, the switch has two states, off and on, and it changes from one to the other each time it is accessed. Table 5-3 describes the speaker output characteristics. The speaker circuit is described in the section "The Speaker," in Chapter 11. • Table 5-3 Speaker output characteristics Port number None Commands Some programs sound the speaker in response to Control-G Initial characteristics Reset routine sounds the speaker Hardware location $C030 Toggle speaker (read only) Monitor firmware routines Location Name Description $FBDD Belli Sends a beep to the speaker $FF3A Bell Sends Control-G to the current output Using the speaker If you switch the speaker once, by reading $C030, it emits a click; to make longer sounds, access the speaker repeatedly. The switch for the speaker uses memory location $C030. You can make various tones and buzzes with the speaker by using combinations of timing loops in your program. A Important You should always use a read operation to toggle the speaker. If you write to this soft switch, it switches twice in rapid succession, A CHAPTER 5 Keyboard and Speaker 135 Monitor firmware support for speaker output The Monitor supports the speaker with one simple routine, Belli. A related routine, Bell, supports the current output device—the one that CSW points to. Belli Belli (at address $FBDD) makes a beep through the speaker by generating a 1 kHz tone in the speaker for 0.1 second. This routine scrambles the A and X registers. Bell The Monitor routine Bell (at location $FF3A) writes a bell control character (ASCII Control-G) to the current output device. This routine leaves the A register holding $87. 136 Apple He Technical Reference Chapter 6 Video Output The primary output device of the Apple lie is its video display. This chapter describes the way the firmware and memory of the Apple Ilc-family computers are used to control the video display. • r 137 You can use any ordinary color or monochrome video monitor with the Apple lie or Apple He Plus. An ordinary monitor is one that accepts NTSC-compatible composite video. If you use Apple He color graphics with a black- and-white monitor, the display appears as black, white, and two shades of gray. • Note: NTSC stands for National Television Standards Committee, a group that formulates TV transmission and reception standards in the USA and several other countries. If you are using only graphics modes and 40-column text, you can use a television set for your video display. If the TV set has an input connector for composite video, you can connect it directly to your Apple He or Apple lie Plus; otherwise, you must attach an RF video modulator between the computer and the television set. • Note- The DB-15 video expansion connector on the back of Apple Ilc-family computers can be used for connecting RF modulators, LCD displays, and other devices designed for use with the Apple lie family. Notice, however, that the video expansion port does not directly support RGB displays, and so cannot be used with the the Apple Color RGB monitor used with the Apple 1IGS® computer. The video expansion connector is described in the section "Video Expansion Output" in Chapter 11. A Important The Apple He family can produce an 80-column text display. However, if you use an ordinary color or black-and-white television set, 80-column text will be too blurry to read. For a clear 80-column display, you must use a high- resolution video monitor with a bandwidth of 14 MHz or greater, A Table 6-1 lists characteristics of the video output port and points to figures and tables where you can find information about these characteristics. 138 Apple He Technical Reference Table 6-1 Video output port (port 3) characteristics Characteristic Where to find more InfonnaUon Commands Figure 6-1 "Text Modes and How to Switch Between Them" Initial characteristics' Figure 6-1 "Text Modes and How to Switch Between Them" Video display page locations Table 6-8 "Video Display Page Locations" Monitor firmware routines Table 6-12 "Monitor Firmware Routines" I/O firmware entry points Table 6-13 "Port 3 Firmware Protocol Table" • Note: On the Apple He computers, your program should check the position of the 80/40 switch at $C060 (bit 7 = 1 indicates 40 columns) and set the number of columns accordingly. See Table 6-9. The Apple He Plus does not have an 80/40 switch. Video display specifications Table 6-2 summarizes the video display's specifications and provides a further guide to other information in this chapter. • Table 6-2 Video display specifications Display modes 40-column text (map: Figure 6-5) 80-column text (map: Figure 6-6) Lo-Res color graphics (map: Figure 6-7) Hi-Res color graphics (map: Figure 6-8) Double Hi-Res color graphics (map: Figure 6-9) Text capacity 24 lines by 80 columns (character positions) Character set 96 ASCII characters (uppercase and lowercase) Display formats Normal, inverse, flashing, MouseText (Table 6-4) CHAPTER 6 Video Output 139 Table 6-2 Video display specifications (continued) Lo-Res graphics 16 colors (Table 6-5): 40 horizontal by 48 vertical (map: Figure 6-7) Hi-Res graphics 6 colors (Table 6-6): 140 horizontal by 192 vertical (restricted) Black and white: 280 horizontal by 192 vertical (map: Figure 6-8) Double Hi-Res graphics 16 colors (Table 6-7): 140 horizontal by 192 vertical (no restrictions) Black and white: 560 horizontal by 192 vertical (map: Figure 6-9) The video signal produced by the Apple He and Apple He Plus is NTSC-compatible composite color video available at two places on the back panel of the computer: the RCA-type phono jack and the 15-pin D-type connector. Use the RCA-type phono jack to connect a video monitor, and the DB-15 connector for an external video modulator or other video expansion hardware. The video circuit and connectors are described in the section "The Video Display," in Chapter 11. Enhanced video firmware The Apple He has two distinct sets of routines in ROM for displaying text on the screen. The standard video firmware supports all the display output available in the Apple II and Apple II Plus computers. The enhanced video firmware supports the additional features provided by an Apple He computer with an 80-column card installed. Table 6-3 compares the features of the standard video firmware with those of the enhanced video firmware. 140 Apple He Technical Reference Table 6-3 Comparison of standard and enhanced video firmware Feature Standard video firmware Enhanced video firmware Character set Primary Alternate Columns 40 40 or 80 Standard input routine Keyln C3KeyIn Standard output routine COutl C3COutl The primary and alternate character sets are described in the following section, "Text Modes." The standard input and output routines are described in Chapter 4. Your program can activate the enhanced video firmware by transferring control to address SC300. To deactivate the enhanced video firmware from a program, write a Control-U character using the output subroutine COut. Figure 6-1 shows the characteristics of the text display modes and how to switch between them from the keyboard. r CHAPTER 6 Video Output 141 Figure 6-1 Text modes and how to switch between them Power On (ESC)|CQNTHOL)-(Q~) Resets full 40-column window Cursor: checkerboard Input hook: Keyln Output hook: COutl Window: 40 columns, 24 lines Character Set: primary Cursor: square box Cursor: narrow box Input hook: C3Keyln Input hook: C3Keyln Output hook: C3COut1 Output hook: C3COut1 Window: 40 columns, Window: 80 columns, 24 lines 24 lines Character Set: alternate Character Set: alternate 142 Apple He Technical Reference Text modes In all three text modes shown in Figure 6-1, the Apple Ilc-family computers can display all 96 ASCII characters: uppercase and lowercase letters, the ten digits, punctuation marks, and special characters. Each character is displayed in an area of the screen that is seven dots wide by eight dots high. The characters are formed by a dot matrix five dots wide (with a few exceptions, such as underscore), leaving two blank columns of dots between characters in a row. Except for lowercase letters with descenders, the characters are only seven dots high, leaving one blank line of dots between rows of characters. The normal display has white (or other monochrome color used by your monitor) dots on a dark background. Characters can also be displayed as black dots on a white background; this is called inverse video. Text character sets The Apple lie family can display either of two text character sets: the primary set and an alternate set (Table 6-4). The forms of the characters in the two sets are actually the same, but the available display formats are different. The display formats are • normal, with white dots on a black screen • inverse, with black dots on a white screen • flashing, alternating between normal and inverse The Apple He family can display uppercase characters in all three formats—normal, inverse, and flashing—with the primary character set. Lowercase letters can only be displayed in normal format with the primary character set. This feature makes the primary character set compatible with most software written for the Apple II and Apple II Plus, which can display text in flashing format but don't have lowercase characters. The alternate character set trades the flashing format for a complete set of inverse characters. With the alternate character set, the Apple lie family can display uppercase letters, lowercase letters, numbers, and special characters in either normal format or inverse format. It can also display MouseText CHAPTER 6 Video Output 143 You can select between character sets with the alternate-text soft switch (AllChar), described later in this chapter. Table 6-4 shows the character codes in decimal and hexadecimal for the Apple Ilc-family primary and alternate character sets in normal, inverse, and flashing formats. • Table 6 4 Display character sets Primarv character set Alternate character set Hex values Character type Format Character type Format $00-$1F Uppercase letters Inverse Uppercase letters Inverse $20-$3F Special characters Inverse Special characters Inverse $40-$5F Uppercase letters Flashing MouseText $60-$7F Special characters Flashing Lowercase letters Inverse $80-$9F Uppercase letters Normal Uppercase letters Normal $A0-$BF Special characters Normal Special characters Normal $C0-$DF Uppercase letters Normal Uppercase letters Normal $E0-$FF Lowercase letters Normal Lowercase letters Normal Each character on the screen is stored as one byte of display data. The low-order six bits make up the ASCII code of the character being displayed. The remaining two (high-order) bits select format and the group within ASCII. See Table 5-2 for the ASCII value of each character. MouseText The alternate character set contains 32 graphics characters called MouseText in place of the primary set's inverse uppercase characters from $40 through $5F. These graphics are especially convenient to use with a mouse because they can be generated by character codes instead of groups of Hi-Res byte values, and they can be moved around quickly. To use MouseText characters, do the following: 1. Turn on the enhanced video firmware with PR#3 or 3 Control-P. 2 Set inverse mode: use the System Monitor Inverse command or put $3F in location $32, or print Conlrol-0 using C3COutl. 3 Turn on MouseText with PRINT CHR$(27); or pass $1B to COut in the A register. 144 Apple He Technical Reference 4. Print the uppercase letter (or other ASCII character in the range $40 through $5F: @ [ \ ] A or _) that corresponds to the MouseText character you want. 5. Turn off MouseText with PRINT CHR$(24); or pass $18 to COut in the accumulator. 6. Set normal mode: use the Normal command or put SFF in location $32, or print a Control-N. Here is a sample Applesoft program that prints all the MouseText characters: 10 DS=CHR5(4) 20 PRINT PRINT D$;"PR#3" 30 INVERSE 40 PRINT CHRS(27);" ABCDEFGKIJKLMNOPQRSTUVWXYZ[]"_"; 50 PRINT CURS (24) ; 60 NORMAL MouseText characters and their corresponding ASCII characters are shown in Figure 6-2. • Figure 6-2 MouseText characters « @ 6 A K B X V B si C D E F ^ _ G ; +: • : L ^ gg ill p Q R S T U V w c X 3 Y Z 1 • [ ^ ^ \ JL ] 3 1 * CHAPTER 6 Video Output 145 40-column versus 80-column text The Apple He family has two text display modes: 40-column and 80-column. The number of dots in each character does not change, but the characters in 80-column mode are only half as wide as the characters in 40- column mode. Compare the two displays in Figure 6-3. On an ordinary color or black-and-white television set, the narrow characters in the 80-column display blur together; you must use the 40-column mode to display text on a television set. A Apple He Plus There is no 80/40 switch on the Apple Be Plus computer; 80/40-column switching is strictly software controlled, A • Figure 6-3 40-column and 80-column text with alternate character set 1LIST 1,110 10 REM APPLESOFT CHARACTER DEMO 20 TEXT : HOME 30 PRINT : PRINT "Applesoft Char acter Demo" 40 PRINT : PRINT "Which characte r set-" 50 PRINT : INPUT 'Primary 70 IF A$ • "P" THEN POKE 49166, 0 80 IF A* • "A" THEN POKE 49167, 0 90 PRINT : PRINT "...printing th e same line, first" 100 PRINT ' in NORMAL, then INVE RSE, then FLASH:": PRINT 1 1LIST 1,111 11 REM APPLESOFT CHARACTER DEMO 21 TEXT : HOME 31 PRINT ; PRINT "Applesoft Character Demo" 41 PRINT : PRINT "Which character set-" 51 PRINT : INPUT "Primary (P) or Alternate tA) '"-.At 61 IF LEN (A*> < 1 THEN SO 6S LET A« - LEFT« r - o o o • - r i - f i - i - i - r r r r r O J « « N W n N ( M « w v> O O O O O O O O O O O O O ' - ' - ' - ' - i n if> if> v> (/> u i tf> i/> O T - W C 0 ^ U l ( 0 N 0 0 f f l O ' - W r t ^ i i ) ( 0 S 0 0 0 1 o-wnfuxosodiO'-iMnifwaiNoiO) Row 0 $400 1024 1 $480 1152 2 $500 1280 3 $580 1408 4 $600 1536 5 $680 1664 6 $700 1792 7 $780 1920 8 $428 1064 9 $4AS 1192 10 $528 1320 11 $5A8 1448 12 $628 1576 13 $6A8 1704 14 $728 1832 15 $7A8 1960 16 $450 1104 17 $4D0 1232 18 $550 1360 19 $5D0 1488 20 $650 1616 21 $6D0 1744 22 $750 1872 23 $700 2000 162 Apple He Technical Reference Figure 6-6 Map of 80-column text display W ^ ^ ^ * ^^^^TW^WV 9 - ^ ^ $00 $01 SOS 103 $04 SOS $06 •*• ••*.• ".*, :••:*.' •- 4k • 6 • «: Row 0 $400 1024 1 $480 1152 2 $500 1280 3 $580 1408 4 $600 1536 5 $680 1664 6 $700 1792 7 $780 1920 8 $428 1064 9 $4A8 1192 10 $528 1320 11 $5A8 1448 12 $628 1576 13 $6A8 1704 14 $728 1832 15 $7A8 1960 16 $450 1104 17 $4D0 1232 18 $550 1360 19 $5DO 1488 20 $650 1616 21 $600 1744 22 $750 1872 23 $7D0 2000 $00 $01 $02 $03 $04 $05 S06 SO7, 0 1 2 3 4 5 6 1 Auxiliary Memory I CHAPTER 6 Video Output 163 Figure 6-7 Map of Lo-Res graphics display --Nn»ui«isoioir«(iis O O O O O O O O O O O O O O O ' - T - * - » - T - * - i - T - * - » - i - . - , ^ T - T - » - 0 J C \ J C \ 4 C \ J C \ j e M C M 0 J '-cyntmtONioaiO'-ojciTmtoNajoiO'-rtnTrmicNmoio'-riinfifitoNaiO) Row ' - • - • - ' - ' - ' - ^ ' - ' - r N N m N N N N t M M i M n n n n n n o n n n ° $400 1024 1 3 ; $480 1152 \ ' $500 1280 ^ | $580 1408 I ; $600 1536 ]° ; $680 1664 )l $700 1792 j* $780 1920 \y ; $428 1064 \l $4A8 1192 *° | $528 1320 y | $5A8 1448 |* $628 1576 2* $6A8 1704 g | $728 1832 1° ' $7A8 1960 H ] $450 1104 35 ] $4D0 1232 3® | $550 1360 3g | $5D0 1488 J° ; $650 1616 43 I $6D0 1744 ** I $750 1872 J® I $7D0 2000 164 Apple lie Technical Reference o o Q Figure 6-9 Map of Double Hi-Res graphics display aii eniory 1;oc1 !601 i 502 ! tat 1;os we $20 $21 $22 $23 $24 $25 $26 $27 0 1 2 3 4 5 6 \ 32 33 34 35 36 37 38 39 Row —| —| — i \ 0 $2000 8192 \ 1 $2080 8320 2 $2100 8448 3 $2180 8576 I 4 $2200 8704 5 $2280 8832 6 $2300 8960 7 $2380 9088 8 $2028 8232 9 $20A8 8360 10 $2128 8488 K V 11 S21A8 8616 12 $2228 8744 0 +$0000 \ 13 $22A8 8872 \ 14 $2328 9000 + 1024 +$0400 \ 15 $23A8 9128 \ + 2048 +$0800 8272 16 $2050 8400 V 17 $2000 + 3072 +$OC0O 18 $2150 8528 19 $21D0 8656 + 4096 +$1000 20 $2250 8784 i + 5120 +$1400 21 $22D0 8912 22 $2350 9040 + 6144 +$1800 23 $2300 9168 $00 $01 $02 $03 $04 $05 $06 $07/ 7 + 7168 +$1C00 | 0 1 2 3 4 5 6 7 I Auxiliary Memory I 166 Apple lie Technical Reference Monitor support for video display output Table 6-12 summarizes the addresses and functions of the video display support routines the Monitor provides. These routines are described in Appendix F. COut and Coutl are described in more detail in Chapter 4. • Table 6-12 Monitor firmware routines Name Location Description drEOL $FC9C Clears to end of line from current cursor position OEOLZ $FC9E Clears to end of line using contents of Y register as cursor position ClrEOP $FC42 Clears to bottom of window from current cursor position ClrScr $F832 Clears the Lo-Res screen ClrTop $F836 Clears top 40 lines of Lo-Res screen COut SFDED Calls output routine whose address is stored in CSW (normally COutl, Chapter 4); displays character stored in A register COutl $FDF0 Displays a character on the screen (Chapter 4) CROut SFD8E Generates a carriage return character CROutl SFD8B Clears to end of line, then generates a carriage return character HLine $F819 Draws a horizontal line of blocks on Lo-Res resolution screen Home $FC58 Clears the window and puts cursor in upper-left corner of window Plot $F800 Plots a single Lo-Res block on the screen PrBl2 $F94A Sends 1 to 256 blank spaces to the output device whose address is in CSW PrByte $FDDA Prints a hexadecimal byte PrErr $FF2D Sends ERR and Control-G to the output device whose output routine address is inCSW PrHex $FDE3 Prints 4 bits as a hexadecimal number PrntAX $F94l Prints contents of A and X registers in hexadecimal SCRN $F871 Reads color value of a Lo-Res block on the screen SetCol $F864 Sets the color for plotting in Lo-Res mode VTabZ $FQ4 Sets cursor vertical position (setting CV at location $25 does not change vertical position until a carriage return) VLine SF828 Draws a vertical line of Lo-Res blocks CHAPTER 6 Video Output 167 I/Ofirmwaresupport for video output Apple Ilc-family video firmware conforms to the I/O firmware protocol described in Chapter 4. However, it does not support windows other than the full 80-by-24 window in 80-column mode, and the full 40-by-24 window in 40-column mode. The video (port 3) protocol table is shown in Table 6-13. • Table 6-13 Port 3 firmware protocol table Address Value Description $C30B $01 Generic signature byte of firmware cards $C30C $88 80-column card device signature $C30D $ii $C3ii is entry point of initialization routine (PInit) $C30E $rr $C3rr is entry point of read routine (PRead) SC30F $ww $C3ww is entry point of write routine (PWrite) SC310 $ss $C3ss is entry point of the status routine (PStatus). PInit The PInit routine initializes the enhanced video firmware. PInit does the following: • sets a full 80-column window • sets 80Store ($C001) • sets80Col($C00D) • switches on AltChar ($C00F) • clears the screen; places cursor in upper-left corner • displays the cursor 168 Apple He Technical Reference PRead The PRead routine reads a character from the keyboard and places it in the A register with the high bit cleared. It also puts a 0 in the X register to indicate no error before returning to the calling program. PWrite The PWrite routine displays a character on the screen or executes a control-character command, as shown in Table 6-14. Your program should place a character in the A register with its high bit cleared before calling PWrite. PWrite does the following: • turns the cursor display off • if the character in the A register is a control character, carries out control functions as shown in Table 6-14 • if the character in the A register is not a control character, checks the inverse flag (location S32) and turns the high bit on for normal display or off for inverse display • if the character is not a control character, displays the character at the current cursor position and advances the cursor • if the cursor is advanced past the end of a line, does carriage return but not line feed When PWrite has completed this, it • turns the cursor display back on (if it was not intentionally turned off by a Control-F command) • puts a 0 in the X register to indicate no error and returns to the calling program CHAPTER 6 Video Output 169 Table 6-14 Video control functions Control- Hex Function Eore $05 Turns cursor on (enables cursor display) Forf $06 Turns cursor off (disables cursor display) Gorg $07 Sounds bell (beeps) Horh $08 Moves cursor left one column; if cursor was at beginning of line, moves it to end of previous line Jorj $0A Moves cursor down one row; scrolls if needed Kork SOB Clears to end of screen Lorl $0C Clears screen; moves cursor to upper-left position on screen M or m $0D Moves cursor to column 0 Norn $0E Displays subsequent characters in normal video; characters already on display are unaffected Ooro $0F Displays subsequent characters in inverse video; characters already on display are unaffected Vor v $16 Scrolls screen up one line; clears bottom line Worw $17 Scrolls screen down one line; clears top line Yory $19 Moves cursor to upper-left (home) position on screen Zorz $1A Clears entire line that cursor is on lor\ $1C Moves cursor right one column; if at end of line, does Control-M lor] $1D Clears to end of the line the cursor is on, including current cursor position; does not move cursor Aor6 $1E GOTOxy: Initiates a GOTOxy sequence; interprets the next two characters as x+32 and y+32, respectively $1F If not at top of screen, moves cursor up one line PStatus The PStatus routine returns the I/O status of the enhanced video firmware. A program that calls PStatus must first put a request code in the A register: either a 0 (meaning "is the enhanced video firmware ready for output'") or a 1 (meaning "is there any input—that is, has a character been typed on the keyboard?"). PStatus returns with the reply in the c flag (the carry flag): 0 (no) or 1 (yes). If the request was not 0 or 1, PStatus returns with a 3 in the X register, indicating an illegal operation. If the request was a 0 or 1, PStatus returns with a 0 in the X register indicating no error. 170 Apple lie Technical Reference Chapter 7 Serial Port I/O The Apple Ilc-family computers have two serial I/O ports. Although these ports are electrically identical, they are set up differently when they are initialized by the reset routine. Port 1 is initialized as an output port for RS-232 type devices, such as printers and plotters. Port 2 is set up to operate as a serial communications port for modems and similar devices. Either port can be reconfigured by software after initialization. Guidelines for making changes for each port are given in this chapter. The serial port back-panel connectors and interface circuitry are described in Chapter 11. • 171 A Important Although the Apple Ilc-family serial ports are similar to the Apple lie Super Serial Card, there are important differences. Refer to Appendix D for a summary of these differences, A A Apple lie Plus Although the Apple lie Plus serial port connectors are identical to AppleTalk connectors, the Apple He Plus does not contain firmware support for AppleTalk. A Sending commands to the serial ports The two following sections describe how to send commands to serial ports 1 and 2. Table 7-1 describes all the commands used by the Apple Ilc-family serial ports. Both ports use the same set of commands. Using serial port 1 You can access the firmware from BASIC by issuing Control-D (if DOS or ProDOS is in RAM) and PR#1. Subsequent output is directed to the printer (or other device) connected to serial port 1. To direct Pascal output to the printer, you can use either #6: or PRINTER:. Your non-Pascal programs can also access the port by changing the value of CSW (see Chapter 4). Table 7-1 lists the commands you can use with serial port 1, either from a program or from the keyboard, after you issue PR#1. Each command must be preceded by Control-I (the command character). As soon as you issue the command character, the serial port firmware displays a flashing question mark cursor to indicate it is awaiting a command. You do not have to press Return after commands that you have entered from the keyboard, or send the return character from your program if it is sending commands to the port. You can type more than one command on a line, but each must be preceded by the command character. 172 Apple He Technical Reference The serial port 1 command character is set as Control-1 when the Apple lie or Apple He Plus is turned on. You can change it to a different control character by sending the current control character followed immediately by the new control character you want. This is useful if you want to be able to send Control-I to the printer without firmware intervention. For example, to change the command character from Conlrol-I to Control-V, send Control-I Control-V either from the keyboard or from a program. (Control-V and Control-W are the recommended substitute control characters.) To change the command character back again, send Control-V Control-I. Don't slip any spaces between the control characters that you send. A Warning Do not use Control-A, -B, -C, -H, -J, -L, -M, or -Y: Apple Ilc-family firmware may intercept these control characters, causing unpredictable results, A The following are examples of valid commands and command sequences. These examples all show commands being entered from the keyboard, but your programs can send the characters just as well. Remember to issue a PR#1 before starting to send commands to serial port 1. • Note- The spaces shown in the following commands are for clarity only; don't include spaces in the actual command string. To echo output to the display screen: Control-I I To set line width 72, disable line feed, and echo: Control-I K Control-I 7 2 N To change control character to Control-V: Control-I Control-V Return To set up the serial port to allow sending Control-I as part of a character stream: Control-V (command} Return CHAPTER 7 Serial Port I/O 173 Using serial port 2 You can access the firmware from BASIC in the usual way—that is, by issuing Control-D (if DOS or ProDOS is in RAM) followed by IN#2 or PR#2. Subsequent input and output are routed through the modem (or other device) connected to serial port 2. A Important In terminal mode, the modem port commands listed in Table 7-2 must follow Control-D and IN#2 (not PR#2) and the command character (which is usually Control-A). A To transfer files to the modem under Pascal, specify REMOUT: or #8:. To transfer files from the modem under Pascal, specify REMIN: or *1\. Table 7-1 lists the commands you can use with serial port 2, either from a program or from the keyboard, after you issue IN#2. Each command must be preceded by Conlrol-A (the command character). As soon as you issue the command character, the serial port firmware displays a flashing question mark cursor to indicate it is awaiting a command. If you press Return, you get the current video cursor again. You do not have to press Return (or send a return character) after commands. You can type more than one command on a line, but each must be preceded by the command character. When the Apple He or Apple He Plus is turned on, the serial port 2 command character is defined as a Control-A. You can change it to a different control character by typing the current control character followed immediately by the new control character you want. This is useful if you want to be able to send Control-A to the output device without firmware intervention. For example, to change the command character from Control-A to Control-V, send Control-A Control-V either from the keyboard or from a program. (Control-V and Control-W are the recommended substitute control characters.) To change the command character back again, send Control-V Control-A. A Warning Do not use Control-B, -C, -H, -I, -J, -L, -M, or -Y: Apple Ilc-family firmware may intercept these control characters, causing unpredictable results, A 174 Apple lie Technical Reference The following are examples of valid commands and command sequences. These examples show commands being entered from the keyboard, but your programs can send the characters just as well. To enable echo to the screen: Control-A I To send a break character to a remote device: Control-A B To change the control character to Control-V (for example, so you can send Control-A as part of a character stream): Control-A Control-V Control-V(command) Serial port command set A Original He The following commands (from Table 7-1) are not available for the original Apple He: C F M X. A CHAPTER 7 Serial Port I/O 175 Table 7-1 Serial port commands Command Description nnn Sets new line width of nnn (from 1 through 255). This command must be followed by N (see nnnN) or by a carriage return. nnB Sets transmission rate to value corresponding to nn. m Baud m Baud Baud 1 5(3 (, 300 11 3600 2 75 7 600 12 4800 3 110 (109.92) 8 1200 13 7200 4 135 (134.58) 9 1800 14 9600 5 150 10 2400 15 1920 When enabled, this command causes a carriage return character to be sent automatically whenever the column count exceeds the printer line width. The command is normally enabled. »D Sets data format to values corresponding to «.• n Data bits Stop bits n Data bits Stop bits 0 8 1 4 8 2 1 7 1 5 7 2 2 6 1 6 6 2 3 5 1 7 5 2 When this command is enabled, your Apple Ilc-family computer accepts data from the keyboard as well as from the serial port. You can use this to disable the keyboard before receiving or sending data to prevent accidental keystrokes from disrupting the data flow. Be sure that your program reenables the keyboard when the data transfer is complete. This command is available only from BASIC and is normally enabled. 176 Apple lie Technical Reference Table 7-1 Serial port commands (continued) Command Description 1 Echoes printer output on the screen, K Disables automatic line feed after carriage return. Lt Generates line feed after carriage return. Normally, this command is enabled. Disabling it has the same effect as the K command. M' When this command is enabled, all incoming line feed characters that are not immediately preceded by carriage return characters are masked (removed from the data stream). Normally this command is enabled. nnnN Changes line width to nnn (from 1 through 255; nnn is optional); does not echo printer output on the screen. Note: ON does not disable automatic generation of carriage return; to do so, use Z command, put 0 directly in location $0579, or use the system utilities disk. nP Sets parity corresponding to «: X Parity M Parity 0 None 4 None 1 Odd 5 MARK (1) 2 None 6 None 3 Even 7 SPACE (0) Q Quit terminal mode. R Resets port and exits from serial port firmware. S Sends a 233-millisecond BREAK character (used with some printers to synchronize with serial ports). T Starts terminal mode. Use after IN#2 only. If followed by PR#2, the computer echoes input to output. CHAPTER 7 Serial Port 1/0 177 Table 7-1 Serial port commands (continued) Command Description X* When enabled, this command turns on the XON/XOFF protocol: the computer looks for the XOFF ($13) character and responds by halting transmission until an XON ($11) is received. Normally this command is disabled. Z Zaps (ignores) further command characters until Control-Reset or PR#1. Does not format output or insert carriage returns into output stream. Control-T When issued by a remote device after the IN#1 or IN#2 command is already in effect, this command puts the Apple lie or Apple He Plus in terminal mode. This command cannot be issued locally; it has the same effect as Control-A T typed locally. Control-Q When issued by a remote device after the IN#1 or IN#2 command is already in effect, this command causes the Apple He or Apple He Plus to quit terminal mode. This command cannot be issued locally; it has the same effect as Control-A Q typed locally. ' Not available on the original Apple He. This command can be toggled: If you follow the command with E (with no intervening space), the command is enabled. If you follow the command with D (with no intervening space), the command is disabled. t The L command is available for all versions of the Apple lie, but cannot be toggled on the original Apple He. • Note-. The commands are letter-type commands, not control characters. 178 Apple He Technical Reference Port 1 This section describes the characteristics and use of port 1 when configured as a printer port. Table 7-2 summarizes the characteristics of port 1. If you change port 1 to a communication port (like port 2), refer to the section "Port 2," later in this chapter, for a description of its use. • Table 7-2 Serial port 1 characteristics Port number Serial port 1. Commands Keyboard command: PR#1. BASIC command: PR#1. Monitor command: 1 Control-P (does not work if there is an operating system in RAM). All other commands: See Table 7-1. Initial characteristics See "Characteristics of Port 1 at Startup." Hardware page locations See Table 7-3. Monitor firmware routines None. I/O firmware entry points See Table 7A. Use of screen holes See Table 7-5. Use of other pages None. Characteristics of port 1 at startup After power-up, the printer firmware sets the following configuration: • 9600 baud • eight data bits, no parity bits, two stop bits • 80-column line width; no echo to display screen • firmware supplies line feed after carriage return • command character is set to Control-I CHAPTER 7 Serial Port I/O 179 These values are stored in the auxiliary memory screen holes (Table 7-5). You can change some of these settings from the keyboard by typing P R # 1 , the command character, and one of the commands listed in Table 7-1. How port characteristics change as a result of various activities is described under "Changing Port 1 Characteristics" later in this chapter. Hardware page locations for port 1 Table 7-3 lists for serial port 1 the addresses and bit assignments of its hardware registers on page $C0. The registers are internal to a 6551 ACIA; their bit assignments are described in Chapter 11. A Warning This table is for your information only. To avoid having problems with the system, you should never \ry to directly access the hardware. Instead, use the firmware routines from the Apple Ilc-family ROM described in Appendix F. • • Table 7-3 Port 1 hardware page locations Location Description $C090-$C097 Reserved $CfJ98 ACIA transmit/receive data register $0099 ACIA status register $C09A ACIA command register $C09B ACIA control register $C09C-$C09F Reserved I/O firmware support for port 1 Table 7-4 lists the locations and values of the I/O firmware protocol table. This standardized protocol is available for use by any application program. Chapter 4 describes how to use this protocol. 180 Apple lie Technical Reference Table 7-4 Port 1 I/O firmware protocol Address Value Description $C105 $38 Pascal ID byte. $C107 $18 Pascal ID byte. $C10B $01 Generic signature byte of firmware cards. $C10C $31 Same ID as for Super Serial Card. $C10D $ii SCIii is entry point of initialization routine (PInit). SC10E Srr SClrr is entry point of read routine (PRead). SC10F $ww SClww is entry point of write routine (PWrite). SC110 $ss SClss is entry point of the status routine (PStatus). $C111 non-zero No optional routines. Screen hole locations for port 1 Table 7-5 lists the screen hole locations that serial port 1 uses. The auxiliary memory locations are reserved for startup value settings which are listed and interpreted in the table. • Table 7-5 Port 1 screen hole locations Location Description Auxiliary memory screen holes (firmware loads values at power up) $0478 $9E (ACIA control register: 8 data + 2 stop bits, 9600 baud) $0479 $0B (ACIA command register: no parity) $047A $40 (flags: no echo, auto LF after CR, type of serial port) Bit Interpretation 7 Echo output on display (0 = no echo) 6 Generate LF after CR(0 = no LF) 5-1 Always = 0 (reserved) 0 1 • communication port; 0 = serial printer port. $047B $50 (printer width: 80 columns) CHAPTER 7 Serial Port 1/0 181 Table 7-5 Port 1 screen hole locations (continued) Location Description Bit Interpretation 7-0 Printer width (0 = do not insert CR) Main memory screen holes $0479 Reserved $04F9 Reserved $0579 Printer width (1-255; 0 = disable formatting) $05F9 Temporary storage location $0679 Bit 7 = 1 while the firmware is parsing a command string $06F9 Current command character (initially Conlrol-I) $0779 Bit 7 = 1 if echo to display is on; bit 6 = 1 if firmware is to generate a LF after CR $07F9 Current printer column Changing port 1 characteristics Figure 7-1 is a diagram of where the port characteristics are stored and moved under different circumstances. You can see the following from the figure: • When the power is first turned on, the reset routine moves the predefined startup characteristics listed earlier in this section from ROM into the auxiliary memory screen holes listed in Table 7-5. • If you specify new characteristics using the system utilities, the system utilities software changes the values in the auxiliary memory screen holes. Your programs can do the same thing. • The values stored in the auxiliary memory screen holes are affected by power-on reset, but not by either Command-Control-Reset or a simple Control-Reset. This feature is provided so that a port that has been reconfigured will remain that way while some other program (such as an application program) is started up. (See Figure 7-1.) • PR#1 causes the firmware to move the characteristics stored in the auxiliary-memory screen holes into the main-memory screen holes. 182 Apple lie Technical Reference A program can change values in the main-memory screen holes directly. However, the only value guaranteed to be in the same place for the entire Apple II series is the line length in main-memory location $0579. The firmware uses the port as it is defined in the main-memory screen holes at any given time. You should use the commands listed in Table 7-1 to change them. Figure 7-1 Diagram of port 1 characteristics storage System Utilities Disk Printer Port PIN Number Selection Commands Port 1 Portl Portl Values in Auxiliary RAM Main RAM Firmware Locations Screen Holes Screen Holes Data format and communication rate Serial data transfer consists of a string of l's and 0's sent down a wire at a prearranged rate of transmission, measured in baud. Before transfer begins, both sender and receiver look for a continuous value of 1: this is called the carrier (see Figure 7-2). When the value goes to 0, the receiver presumes it is a start bit—that is, the bit that designates the beginning of a character of data. If it lasts longer than a bit could possibly last, it is considered a BREAK signal, which some printers use for synchronization. CHAPTER 7 Serial Port I/O 183 If the first 0 proves to be a bit, it is interpreted as the start bit. Next come the seven or eight data bits (six is seldom used with computers), low-order bit first. If parity is on, it comes next in the message. Finally, one or two stop bits appear. The stop bits have a value of 1, like the carrier. The next start bit begins transfer of the next character of data. The parity bit provides a simple check of data validity. Odd parity means the sender counts the number of l's among the data bits, and sends the appropriate parity bit to make the total number of l's odd. With even parity, the sender adds the appropriate parity bit to make the total number of 1 bits even. MARK parity is always a 1 bit; SPACE parity is always a 0. The receiver can then check that the parity bit is correct. If the transmission rate is 300 baud and the data format is one start bit plus seven data bits plus one parity bit plus one stop bit (totaling ten bits transmitted for each byte of data sent), then the actual transfer rate is about 30 characters per second. • Figure 7-2 Data format n- 1 or MARK or SPACE Start + - 7 a ^ No Odd »Data + • Even MARK I Parity + { l Stop i SPACE t. 4 LSB MSB Carrier 1 0 0 0 0 I Start Odd Stop Next Bit Parity Bit Start Bit ASCII letter M = $4D; sent as 8 data, odd parity, 1 stop bit 184 Apple He Technical Reference Carriage return and line feed If you are using a typewriter and you push the carriage all the way to the right (in other words, position the printing mechanism at the left margin), you have performed a carriage return. On the other hand, turning the platen so the paper moves to the next line (or using the index key on an electric typewriter) is called a line feed. Most typewriters perform a line feed automatically after a carriage return, and so the two seem to be one—but they are not. Carriage return and line feed are separate ASCII codes. Carriage return is sometimes denoted CR; it is ASCII code $0D (13). Line feed, sometimes denoted LF, is ASCII code $0A (10). Down Arrow on all Apple Ilc-family keyboards generates a LF. Some printers can supply a line feed automatically after detecting a carriage return; others cannot. If the printer does not supply a line feed after a carriage return and it is not supplied in the data stream, the printer keeps printing over and over on the same line. On the other hand, if both the printer and the computer firmware supply LF after CR, double line-spacing results. If the print head keeps moving too far to the right across the page and then prints many characters on top of one another on the right, then the firmware should be instructed to furnish CR after a certain line width has been reached. If the printer prints too short a line before moving to the next line, then probably the firmware is using too small a line width. If the printer misses characters at the beginning of each line but otherwise prints correctly, there is probably not enough time for the print mechanism to return to the left margin in response to CR. You must use a lower transmission rate with such a printer. Sending special characters If you want to send special characters (control characters) to the printer without having them intercepted and executed by the computer's firmware, use the Z command (see Table 7-1). If the only special character that causes a problem is the command character (normally Control-I for port 1), you can change just the command character instead of using the zap (Z) command. If you use the zap command, the firmware does no formatting; that is, it does not check line width or insert carriage returns or line feeds. This may be necessary to send graphics to a printer or plotter. ' CHAPTER 7 Serial Port I/O 185 Displaying output on the screen You can display printer output on the screen, but if the printer line width exceeds the 40 or 80 columns you have selected for display, you should turn off video display. Port 2 This section describes the characteristics and use of port 2 when configured as a communication port. Table 7-6 summarizes the characteristics of port 2. If you change port 2 to a printer port (like port 1), refer to the section "Port 1," earlier in this chapter, for a description of its use. • Table 7-6 Serial port 2 characteristics Port number Serial port 2. Commands Keyboard commands: IN#2 before Table 7-1 commands, IN#2 to accept port 2 input, PR#1 to echo input to printer, PR#2 to echo input back to port 2. BASIC commands: same. Monitor command: 2 Control-P (does not work if there is an operating system in RAM). All other commands: see Table 7-1. Initial characteristics See "Characteristics of Port 2 at Startup." Hardware page locations See Table 7-7. Monitor firmware routines None. I/O firmware entry points See Table 7-8. Use of screen holes See Table 7-9. Use of other pages In terminal mode, firmware uses auxiliary memory locations $0800-$087F to store keyboard input, and $0880-$08FF as a serial input buffer. 186 Apple lie Technical Reference Characteristics of port 2 at startup After power-up, the firmware sets the following configuration: • 300 baud • eight data bits, no parity bits, one stop bit • firmware does not supply line feed after carriage return • firmware does not insert carriage returns into output stream • firmware does not echo output to the display screen • command character is set to Control-A These values are stored in the auxiliary memory screen holes (see Table 7-9). You can change some of these settings from the keyboard using the command character followed by one of the commands listed in Table 7-1. How port characteristics change as a result of various activities is described later in this chapter. If you change any of these values using keyboard commands or commands from a program, subsequent accesses to the port firmware (even by another program) use the new settings instead of the power-up values. This allows you to change the settings once at system startup and get the desired configuration for subsequent uses. Hardware page locations for port 2 Table 7-7 lists for serial port 2 the addresses of its hardware registers on page $C0. The registers are internal to a 6551 ACIA; their bit assignments are described in Chapter 11. A Warning This table is for your information only. To avoid having problems with the system, you should never try to directly access the hardware. Instead, use the firmware routines from the Apple Ilc-family ROM described in Appendix F. • CHAPTER 7 Serial Port 1/0 187 Table 7-7 Port 2 hardware page locations Location Description $C0A0-$C0A7 Reserved $C0A8 ACIA transmit/receive data register $C0A9 ACIA status register $C0AA ACIA command register $C0AB ACIA control register $C0AC-$C0AF Reserved I/O firmware support for port 2 Table 7-8 lists the values in the I/O firmware protocol table for serial port 2. This standardized protocol is available for use by any application program. Chapter 4 describes how to use this protocol. • Table 7-8 Port 2 I/O firmware protocol Address Value Description SC205 $38 Pascal ID byte. $C207 $18 Pascal ID byte. $C20B $01 Generic signature byte of firmware cards. $C20C $31 Same ID as for Super Serial Card. $C20D $ii $C2ii is entry point of initialization routine (PInit). $C20E $rr $C2rr is entry point of read routine (PRead). $C20F $ww $C2ww is entry point of write routine (PWrite). $C210 $ss $C2ss is entry point of the status routine (PStatus). $C211 nonzero No optional routines. 188 Apple He Technical Reference Screen hole locations for port 2 Table 7-9 lists the screen hole locations that serial port 2 uses. Note that the auxiliary memory locations are reserved for startup value settings. • Table 7-9 Port 2 screen hole locations Location Description Auxiliary memory screen holes (firmware loads values at power-up) $047C $16 (ACIA control register: 8 data + 1 stop bit, 300 baud) $047D $0B (ACIA command register: no parity) $047E $01 (flags: no echo, no auto LF after CR, communication port) Bit Interpretation 7 Echo output on display (0 = no echo) 6 Generate LF after CR (0 = no LF) 5-1 Always = 0 (reserved) 0 1 = communication port; 0 = serial printer port $047F $00 Cine length: do not add any CR to output stream) Bit Interpretation 7-0 Line length (0 = do not insert CR) Main memory screen holes $047A Reserved $04FA Reserved $057A Line length (1-255; 0 = disable formatting) $05FA Temporary storage location $067A Bit 7 = 1 if and only if the firmware is currently parsing a command string $06FA Current command character (initially Control-1) $077A Bit 7 = 1 if echo to display is on; bit 6 = 1 if firmware is to generate a LF after CR $07FA Current column CHAPTER 7 Serial Port 1/0 189 Changing port 2 characteristics Figure 7-3 is a diagram of where the port characteristics are stored and moved under different circumstances. You can see the following from the figure: • When the power is first turned on, the reset routine moves the predefined startup characteristics listed earlier in this section from ROM into the auxiliary memory screen holes listed in Table 7-9. • If you specify new characteristics using the system utilities, the utility software changes the values in the auxiliary memory screen holes. • The values stored in the auxiliary memory screen holes are affected by power-on reset, but not by either Command-Control-Reset or a simple Control-Reset. This feature is provided so that a port that has been reconfigured will remain that way while some other program (such as an application program) is started up. • IN#2 causes the firmware to move the characteristics stored in the auxiliary memory screen holes into the main-memory screen holes. • A program can change values in the main-memory screen holes directly. However, the only value guaranteed to be in the same place for the entire Apple II series is the line length in main memory location $057A. • The firmware uses the port as it is defined in the main-memory screen holes at any given time. You should use the commands listed in Table 7-1 to change these characteristics. 190 Apple He Technical Reference Figure 7-3 Diagram of port 2 characteristics storage System Utilities Disk Communication Port PIN Number Selection Commands (See Appendix H) (See Table 8-2) Port 2 Port 2 Port 2 Main RAM Values in Auxiliary RAM Screen Holes Firmware Locations Screen Holes (See Table 8-5) (See Table 8-5) Reserved Screen Holes Data format and transmission rate A noteworthy characteristic of data communication is its strangeness: sometimes the oddest changes make a given communication arrangement work or not work. You must keep this notion firmly in mind when working with a serial port set up as a communications port. For example, modem communication involves quite a few elements (see Figure 7-4): • the Apple Ilc-family computer and its firmware, with the transmission rate, data format, and other characteristics you have selected • the cable from the computer to the modem • the modem • possibly an acoustic coupler for a telephone handset CHAPTER 7 Serial Port I/O 191 • the telephone lines and switching equipment • some combination of modem, cable, and remote computer or terminal at the distant end As you can imagine, some care is required for successful data transmission. If you have problems, change only one variable at a time and then cycle through the other variables one at a time. Take nothing for granted. The data format advertised for an information service, for example, may be different from the one you end up using with the Apple Ilc-family computer. • Figure 7-4 Devices in a typical communication setup Local DTE Local DCE Transmission Line Remote DCE Remote DTE (Data Terminal (Data Communication Equipment) Equipment) 192 Apple He Technical Reference Carriage return and line feed If you are communicating with a computer or terminal, carriage return and line feed may or may not be involved. Start off without generating them, and turn on automatic generation only as needed. They are described fully under this same heading in the section on port 1. Routing input and output This section discusses the possible ways that serial port 2 can route information. Sometimes the cause of communication problems is that information is not going where you think it is, or it is and you cannot see evidence of the fact. Figures 7-5 through 7-8 show some of the patterns of information flow you can select. It is best to read all this material as a unit; questions that arise while you read one description may be answered elsewhere. The simplest serial port 2 command is IN#2 (see Figure 7-5). Port 2 becomes the input device. Data coming into the port gets passed to the input buffer (page $02 of main memory). Applesoft firmware and system software can see the data and carry out commands in the normal way. Of course, you can also use just the PR#2 command—for example, if you want to send a listing to the modem. To use port 2 for data communication, you ordinarily put it into terminal mode. Following IN#2, pressing Control-A gets the attention of the port 2 firmware, which displays a blinking question mark (?) as a prompt. Now type T to put the computer in terminal mode. In this mode, the firmware displays a blinking underscore character ( _ ) as a prompt. Terminal mode is further described in the section Terminal Mode," later in this chapter. In the discussion that follows, local refers to your Apple Ilc-family computer. Remote refers to some other device, usually in a distant location and at the other end of a communication link. The remote device can be any ASCII-generating unit: a terminal or a computer. If a remote computer is another Apple Ilc-family member or an Apple II-series machine with a Super Serial Card in it, then most of the commands described here apply to it as well. CHAPTER 7 Serial Port I/O 193 Figure 7-5 Effect of IN#2 Remote Communication « - Communication Device Device 1 m rnvid ri2 Port 1 Port 2 FW FW Remote Terminal MON -4 ' or Computer Keyboard Half-duplex operation In half-duplex operation, information can flow from A to B or from B to A, but in only one direction at a lime. In a half-duplex setup, the host does not echo back to the terminal what the terminal sends it. For half-duplex operation, use IN#2 and Control-A T (Figure 7-6) whether the Apple He family member is the host or the terminal. IN'2 plus Control-A T is the best way to set up the computer for auto-answer operation. The T command allows port 2 firmware to exchange information with the local modem without interference from the local firmware or system software. (The remote device can always cancel the T command with Control-R if necessary, and restore terminal mode with Control-T.) Avoiding PR#2 at this point means that the Apple lie family member can operate as a half-duplex terminal, half-duplex host, or full-duplex terminal. (The remote device can also issue Control-A PR#2 if PR#2 is required at the local computer.) 194 Apple lie Technical Reference Figure 7-6 Effect of IN#2 and T command, half duplex Display Jl Communication Remote Printer Device •0- Communication U. Device L2 vid f(PR»1) 1 . 0) c Port 1 Port 2 FW FW Remote Terminal MON or Computer Keyboard In half-duplex operation, the output hook is available for other uses. For example, you can issue PR#1 to print incoming messages from port 2. Use the Control-A I command to display information on the screen. CHAPTER 7 Serial Port I/O 195 Full-duplex operation In full-duplex operation, information can flow from A to B and from B to A simultaneously. Typically, one of the computers (the host computer) echoes its input to output, so the other computer (the terminal) can easily verify that the communication is taking place. Figure 7-7 shows the flow of information when the Apple Ilc-family computer is a full-duplex terminal. (The setup commands, IN#2 and Control-A T, are the same as for half duplex.) • Figure 7-7 Effect of IN#2 and T command, full-duplex terminal \ Remote _*_j Communication Printer Device -0- Communication k? Device PR#1 !< > (I)"! •- Port 1 p*- Port 2 K2Echo FW MON c FW Remote Terminal or Computer Keyboard 196 Apple lie Technical Reference If your Apple Ilc-family computer is the terminal in full-duplex operation, use the N command to turn off echoing input to the screen. If the computer does echo input to Hie screen in this setup, everything you type will appear twice: once from the Apple Ilc-family computer and once from the host computer. In this mode of operation, if you echo input to the printer you can get a printed record of both sides of the communication session: the input from the host, and the Apple Ilc-family computer output as echoed by the host. Figure 7-8 shows the flow of information when the Apple Ilc-family computer is a full-duplex host. In this case, the local Apple lie must echo input to output for the remote device. The setup commands include PR#2 in this case. CHAPTER 7 Serial Port I/O 197 Figure 7-8 Effect of IN#2, PR#2, and T command, full-duplex host Display rt Jl Communication Remote Printer «" Communication ^ = Device Device 1 r~i v i d ^ f f Port 1 FW r MON Port 2 FW V^jicho (No Echo) Remote Terminal or Computer Keyboard A Warning If the Apple Ilc-family computer echoes input to output and the other computer does too, then the first subsequent keypress echoes back and forth endlessly and lock up the Apple Ilc-family computer. This requires a Control- Reset to get out. If you echo input to output when using an information service, the host ends up seeing the echo of what it sent you as though you had typed it. A 198 Apple He Technical Reference When the Apple Ilc-family computer is a full-duplex host, the local output hook is not available for using the printer or other device. To display keyboard and port 2 input on the screen, issue Control-A I. Terminal mode Terminal mode makes the Apple He family member act like a dumb terminal—one that just sends and receives information, but does not process it. Input and output flow through special serial I/O buffers on page $08 of auxiliary memory. Applesoft firmware and system software cannot see or interpret the data: only the serial port 2 firmware deals with it. In most terminal mode setups, the firmware does not display port 2 input unless you use the Control-A I command. • Warning When using terminal mode, $0800-$08FF of auxiliary RAM is used for buffering. Any data stored there is overwritten when terminal mode is enabled, A Control-A T turns on terminal mode, and Control-A Q turns it off. The remote device can go into terminal mode, and then turn off terminal mode al the local Apple lie with the Control-R command. If it then issues Control-A PR#2, local output will go to the remote device. The remote keyboard and display then become the input and output devices of the local Apple He family member's processor. This is called remote mode. In remote mode, the local Apple He family member does not use the serial I/O buffers (as it does in terminal mode); therefore, local firmware and system software detect and interpret all input and output data. So, for example, if you type CATALOG at the remote device keyboard, the local Apple He family member executes the command and lists the disk catalog on the remote device's display. (In terminal mode, the local computer would simply display the word CATALOG on its screen.) The remote device can turn the local Apple lie's terminal mode back on with Control-T. Control-A T issued at the remote device only turns on the remote device's terminal mode, unless the command character there has already been changed to something else. CHAPTER 7 Serial Port I/O 199 Chapter 8 Block Device I/O The Apple lie family supports both built-in and external block devices. Block devices read or write data in groups of bytes called blocks; examples of block devices are 5.25-inch disk drives, 3.5-inch disk drives, and memory expansion cards (that is, RAM disks). Block device I/O is supported by both operating system interface routines and by the SmartPort firmware in the Apple Ilc-family ROM. This chapter describes only the interface routines in the Apple lie and Apple He Plus firmware; to learn about the block device interface for a specific operating system, see the reference manual for that operating system. • 201 Disk drive I/O All Apple Ilc-family disk drives are block devices, but the various versions of the Apple lie provide different levels and types of support for them. The following sections describe disk I/O characteristics for each Apple lie family member. See the section "Disk I/O," in Chapter 11, for descriptions of the disk drive connectors. Original Apple lie In the original Apple He, the I/O firmware entry point for the 5.25-inch drives is at $C600 in the ROM. The internal 5.25-inch drive is port 6, drive 1, and the external 5.25-inch drive is port 6, drive 2. The original Apple lie does not have SmartPort firmware, and thus has no interface for 35-inch disk drives. Table 8-1 summarizes the disk I/O port characteristics of the original Apple He. Table 8-1 Disk port characteristics of the original Apple lie Port number internal 5.25-inch drive port 6, drive 1 (valid boot device) external 5.25-inch drive port 6, drive 2 (not valid boot device) Commands 6 Control-K or 6 Control-P from the Monitor Resets All resets with a valid reset vector, except Control-Reset, eventually pass control to the built-in disk drive. Hardware location $C0E0-C0EF are reserved. Monitor firmware routines None. I/O firmware entry points $C600(port6) Use of screen holes Port 6 main- and auxiliary-memory screen holes are reserved. 202 Apple lie Technical Reference UniDisk 3.5 and memory expansion Apple lie The I/Ofirmwareentry point for the 5.25-inch drives is at $C600 in the main ROM. The internal 5.25-inch drive is port 6, drive 1, and the external 5.25-inch drive is port 6, drive 2. The I/Ofirmwareentry point for the 3.5-inch disk drives is at $C500 in the main ROM. The first 3.5-inch drive in the chain is port 5, drive 1, and the second is port 5, drive 2. Table 8-2 summarizes the disk I/O port characteristics for the UniDisk 3.5 and memory expansion versions of the Apple lie. • Table 8-2 Disk port characteristics of the UniDisk 3.5 and memory expansion Apple lie Port number internal 5.25-inch drive port 6, drive 1 (valid be ' ievice) external 5.25-inch drive port 6, drive 2 (not valid ooot device) first 3.5-inch drive port 5, drive 1 (valid boot device) second 3.5-inch drive port 5, drive 2 (not valid boot device) third 3.5-inch drive port 2, drive 1 (not valid boot device) Commands 5.25-inch drives 6 Control-K or 6 Control-P from the Monitor 3.5-inch drives 5 Control-K or 5 Control-P from the Monitor Resets Ail resets with a valid reset vector, except Control-Reset, eventually pass control to port 6, drive 1 or port 5, drive 1, in that order. (If a memory expansion card is installed, control is passed first to the memory expansion card.) Hardware location $C0DO-C0DF and $C0E0-C0EF are reserved. Monitor firmware routines None. I/O firmware entry points $C600(port6) Use of screen holes Port 6 main- and auxiliary-memory screen holes are reserved CHAPTER 8 Block Device 1/0 203 Apple He Plus The I/O firmware entry point for the 5.25-inch drives is at $C600 in the main ROM. The first (external) 5.25-inch drive is port 6, drive 1, and the second drive is port 6, drive 2. The I/Ofirmwareentry point for the 3.5-inch drives is at $C500 in the main ROM. The internal drive is port 5, drive 1. Thefirstexternal 3.5-inch drive is port 5, drive 2, the second drive is port 2, drive 1, and the third drive is port 2, drive 2. Although the last two 3.5-inch drives in the chain are treated as port 2 devices, they are accessed through the $C500 entry point, just as if they were port 5 devices. Table 8-3 summarizes the disk I/O port characteristics for the Apple lie Plus. Table 8-3 Disk port characteristics of the Apple He Plus Port number first 5.25-inch drive port 6, drive 1 (valid boot device) second 5.25-inch drive port 6, drive 2 (not valid boot device) internal 3.5-inch drive port 5, drive 1 (valid boot device) first external 3.5-inch drive port 5, drive 2 (valid boot device) second external 3.5-inch drive port 2, drive 1 (not valid boot device) third external 3.5-inch drive port 2, drive 2 (not valid boot device) Commands 5.25-inch drives 6 Control-K or 6 Control-P from the Monitor port 5 3.5-inch drives 5 Control-K or 5 Control-P from the Monitor port 2 3.5-inch drives 5 Control-K or 5 Control-P from the Monitor Resets All resets with a valid reset vector, except Control-Reset, eventually pass control to port 5, drive 1; port 5, drive 2; or port 6, drive 1, in that order. (If a memory expansion card is installed, control is passed first to the memory expansion card.) Hardware location $COD0-C0DF and $C0E0-C0EF are reserved. Monitor firmware routines None. I/O firmware entry points 5.25-inch drives $C600 (port 6) port 5 3.5-inch drives $C500(port5) port 2 3.5-inch drives $C500(port5) Use of screen holes Port 6 main- and auxiliary-memory screen holes are reserved 204 Apple He Technical Reference Memory expansion card I/O A memory expansion card can be plugged into the internal connector in the memory expansion Apple He or the Apple He Plus. Such a card provides up to 1 MB of RAM, in 256 KB steps, for storage of program and datafiles.It is not accessed the way main or auxiliary RAM is. Instead, the Apple Ilc-family computers treat the memory expansion card the same way they treat a disk drive: as a block device. Thus, you can think of the memory expansion card as a RAM disk; programs can be loaded into the memory expansion card's RAM, but in order to be executed they must be moved, in whole or in part, to the computer's main memory. The I/Ofirmwareentry point for the memory expansion card is al $C400 in the main ROM of the memory expansion Apple lie and of the Apple lie Plus. The memory expansion card is a block-type device, so I/O operations involving the card use the operating system or the SmartPort I/O interface described later in this chapter. If there is no memory expansion card installed and you execute a ProDOS ON_LINE call to port 4, ProDOS returns error $2D, indicating a SmartPort BadBlock error. If there is no memory expansion card installed and you execute a CAT command from BASIC for port 4, BASIC returns the message PATH NOT FOUND. Pascal returns no error when you formal the RAM disk, even when the memory expansion card is not installed. However, when the memory expansion card is not installed, a UnitStatus call returns 0 blocks available, and if you try to read the volume in port 4, Pascal returns a value of 8 for IOResult, which indicates that there's no room on the volume. When the memory expansion card is not present, the information for port 4 listed by the Vols command in the Pascal Filer includes for the volume name and 0 for the number of blocks. DOS 3.3 does not return any error when you initialize the RAM disk by executing an IN#4 command. However, if you try to read from or write to the RAM disk, DOS 3.3 returns an ONERR error (error code = 8). You can use a Status call in SmartPort to determine if a memory expansion card is installed. This procedure is discussed in the section "SmartPort Status," later in this chapter. CHAPTER 8 Block Device I/O 205 More information on the Apple memory expansion card can be found in the Apple He Memory Expansion Card Technical Reference. A Original He The original and UniDisk 3.5 versions of the Apple He do not support the UniDisk 3.5 memory expansion card, A A Apple He Plus The memory expansion card manufactured by Apple Computer, Inc. for use in the memory expansion Apple lie does not work in the Apple lie Plus computer. To add a memory expansion card to the Apple He Plus, you must purchase a card made by another manufacturer specifically for the Apple lie Plus, A Table 8-4 summarizes the I/O port characteristics of the memory expansion card. Table 8-4 Memory expansion card port characteristics Port number port 4 (valid boot device) Commands 4 Control-K or 4 Control-P from the Monitor Resets All resets with a valid reset vector, except Control-Reset, eventually pass control to the memory expansion card. Hardware location $C0CO-COCF are reserved Monitor firmware routines None. I/O firmware entry points $C400(port4). Use of screen holes Port 4 main and auxiliary memory screen holes are reserved. 206 Apple Ik Technical Reference Using SmartPort The following sections describe the firmware interface that you can use to access and control block devices in your programs. This interface is present in the Apple lie Plus and in all versions of the Apple lie except the original Apple lie. • Protocol Converter.- The SmartPort and the Protocol Converter are essentially the same firmware interface with different names. All the specifications given in this manual for the SmartPort apply to the Protocol Converter as well. Locating SmartPort Your SmartPort routines should always begin with a search for the following signature bytes: $Cn01=$20 $Cn03=$00 $Cn05=$03 $Cn07=$00 The port or slot number, n, can be an integer from 1 to 7. The SmartPort entry point (the dispatch routine) is then found at address $Cn0O + ($CnFF) + 3, where ($CnFF) refers to the value of the byte located at $CnFF. The sample program at the end of this chapter illustrates such a search. There is a SmartPort ID Type byte (Table 8-5) located at $CnFB that indicates which type of device is supported by the SmartPort firmware for that port or slot. For example, the SmartPort ID Type byte for port 4 in the Apple He Plus computer is $01, indicating SmartPort support for a RAM card (a memory expansion card). The ID Type byte for port 5 of all Apple Ilc-family computers (except for the original Apple He, which does not have SmartPort) is $00, indicating SmartPort support for disk drives. CHAPTER 8 Block Device I/O 207 Table 8-5 SmartPort ID Type byte Bit Meaning when bit set 7 Extended SmartPort calls 6 Reserved 5 Reserved •i Reserved 3 Reserved 2 Reserved 1 SCSI devices 0 RAM cards A Important The SmartPort firmware is present in port 4 of the memory expansion Apple He and of the Apple He Plus, even when the memory expansion card is not installed. To check for the memory expansion card, issue a Status call, status code $03, to the port 4 SmartPort. If the data returned indicates 0 bytes available, the card is not present, A Issuing a call to SmartPort SmartPort calls are coded like ProDOS Machine Language Interface (MLI) calls: the program executes a JSR to the SmartPort dispatch routine for the appropriate port. For example, to access the memory expansion card in the Apple lie Plus, your program would execute a JSR to address $C400 + ($C4FF) + 3, where ($C4FF) refers to the value of the byte located at $C4FF. The SmartPort command number and a 2-byte pointer to the call's parameter list must immediately follow the call. Here is an example of a call to the SmartPort firmware: 208 Apple He Technical Reference SPCALL JSR DISPATCH ;Jump to SmartPort command dispatcher entry point DFB CrndNum /Specifies the command type DW CmdList ;2-byte (low, high) pointer to parameter list BCS ERROR ;Sets carry on an error The command number (CrndNum) defines which SmartPort call you want to make. All SmartPort calls include a 2-byte pointer to a parameter list. The parameter list can contain information to be used by the call, or can provide space for information to be returned by the call. The length and content of the parameter list depend on the call being made. The format of each SmartPort call's parameter list is described later in this chapter. • Warning You must leave 35 bytes of stack space available to the block device interface (SmartPort or operating system). All RAM that is accessed by the interface must be both read and write enabled. See the section "Bank-Switched Memory," in Chapter 2, for the commands to read and write enable RAM. You must not pass any data to or from the SmartPort through any zero page locations. SmartPort uses zero page for temporary storage of data, and might corrupt the data you stored there. If you fail to observe these cautions, your program will crash, A When the call has finished, the program resumes execution at the statement following the pointer to the parameter list. In the example above, the DFB and DW statements are skipped and execution resumes with the BCS statement. If the call is successful, the c flag (in the Processor Status register) is cleared (0), and the A register (accumulator) is cleared to all 0's. If the call is unsuccessful, the c flag is set (1) and the error code is placed in the A register. After the SmartPort call, the contents of the 65C02's registers are as shown in Table 8-6. CHAPTER 8 Block Device I/O 209 Table 8-6 Contents of the 65C02 registers after a SmartPort call Register Processor Status PC Bit i Successful call x 0 u X 0 n n 0 JSR+3 Unsuccessful call x 1 0 u X 1 X X Error JSR+3 x = undefined, except in cases where index information is returned in X and Y registers u = unchanged n = number of bytes transferred when the transfer was from the device to the host; otherwise undefined • Warning The extended SmartPort calls available for use on the Apple lies computer cannot be used on the Apple He—family computers. Using an extended SmartPort call causes unpredictable results on an Apple lie or Apple lie Plus. • SmartPort assignment of unit numbers The unit number specifies which device is to respond to the SmartPort command. The unit number is included in every parameter list. Calls that allow you to reference the SmartPort itself use a unit number of $00. Only Status, Init, and Control calls may be made to unit $00. The UniDisk 3.5 Apple He has SmartPort support only for port 5. The memory expansion Apple He and the Apple He Plus have SmartPort support for ports 5 (disk drives) and 4 (memory expansion card). SmartPort assigns unit numbers to devices in ascending order starting with unit number $01. The highest unit number supported by port 5 is S06; however, due to power-supply limitations, $04 is the highest number that should ever be used. For port 4, only unit number $01 is assigned. 210 Apple He Technical Reference In the UniDisk 3.5 and memory expansion versions of the Apple He, the UniDisk 3.5 drive closest to the computer is assigned unit number $01; additional UniDisk 3.5 drives (if any) are assigned unit numbers according to their positions in the daisy chain. In the Apple lie Plus, the built-in disk drive is assigned unit number $01 and additional 3.5-inch disk drives are assigned unit numbers from $02 to $04, according to their positions in the chain. No unit numbers are assigned to 5.25-inch disk drives. • Note: ProDOS 1.1.1 supports only two devices per slot. ProDOS 1.2 and later supports up to four devices on SmartPort. ProDOS 1.2 maps devices $03 and $04 so that they appear to software as if they were connected to port 2. Any external 5.25-inch disk drives must come last in the daisy chain, and are mapped to port 6. External disk drive options The original Apple lie has one internal 5.25-inch disk drive and supports one external 5.25-inch drive. Only the internal 5.25-inch disk drive can be used as a startup device for a cold start. The UniDisk 3.5 Apple lie has one internal 5.25-inch disk drive, and supports one external 5.25-inch drive and one external UniDisk 3.5 drive. If both an external 5.25-inch disk drive and a UniDisk 3.5 drive are used, the 5.25-inch disk drive must come after the UniDisk 3.5 drive; that is, the UniDisk 3.5 drive is attached directly to the computer, and the 5.25-inch drive is connected to the UniDisk 3.5. The possible startup devices for the UniDisk 3.5 Apple lie are, in order of priority, as follows: • internal 5.25-inch drive al SC600 (port 6, drive 1) • external 3.5-inch drive at $C500 (port 5, drive 1) The memory expansion Apple He has one internal 5.25-inch disk drive, and supports up to three external devices plus the memory expansion card. The external devices can be any combination of up to three external UniDisk 3.5 drives and one external 5.25-inch drive. If an external 5.25-inch drive is used, it must be the last device in the daisy chain. CI IAPTER 8 Block Device 1/0 211 The possible startup devices for the memory expansion Apple He are, in order of priority, as follows: • memory expansion card at $C400 (port 4, drive 1) • internal 5.25-inch drive at $C600 (port 6, drive 1) • external UniDisk 3.5 drive at $C500 (port 5, drive 1) The Apple He Plus has one internal 3.5-inch disk drive, and supports up to three external drives plus the memory expansion card. The three external drives can be any combination of up to two 5.25-inch drives, up to three UniDisk 3.5 drives, and one Apple 3.5 drive. An Apple 3.5 drive must come before any UniDisk 3.5 drives in the daisy chain, and any 5.25-inch drives must come last, after any 3.5-inch drives in the daisy chain. The possible startup devices for Apple He Plus are, in order of priority, as follows: • memory expansion card at $C400 (port 4, drive 1) • internal 3.5-inch drive at SC500 (port 5, drive 1) • external 3.5- inch drive al SC500 (port 5, drive 2) • external 5.25-inch drive at $C600 (port 6, drive 1) Booting from 5.25-inch disk drives is handled by the slot 6 firmware. Reading the SmartPort call descriptions The SmartPort call descriptions in this chapter include the following items Command name The name used to identify the SmartPort call. The command name is given as the heading to the SmartPort call description. Command number A 1-byte number that specifies the type of SmartPort call. The command number is contiguous in memory with the JSR instruction to the SmartPort entry point. The command number is included in the heading to the SmartPort call description. 212 Apple He Technical Reference Parameter list A list of the required call parameters. Each SmartPort call includes a 2-byte pointer to the parameter list. The parameter-list pointer is contiguous in memory with the command number. Possible errors A list of the error codes that can be returned by the call. The possible causes of each error are discussed in the section "Summary of SmartPort Error Codes," at the end of this chapter. The parameter list descriptions in this chapter include [he following items. Not all parameter types are used by every SmartPort call. Parameter count A 1-byte number that specifies the number of parameters in the parameter list. The parameter count is the first item in the parameter list. Unit number A 1-bytc value that specifies the device to or from which the SmartPort call is to direct I/O. The unit number is the second item in the parameter list. Buffer address A 2-byte (word) pointer to the start of the block of memory that SmartPort is to use in the I/O transaction. The buffer address is referred to in the parameter description by a name that reflects the use of the buffer; for example, Status list or Control list. Block number A 3-byte number specifying the logical address in a block device of the block of data to be used in an I/O transaction. The block number is translated into a physical address by the controller in the block device. Byte count A 2-byte number specifying the number of bytes to be transferred between memory and the device. Address pointer A 3-byte number specifying an address within the device. The meaning of this number depends on the specific device being accessed. CHAPTER 8 Block Device I/O 213 Generic SmartPort calls Generic SmartPort calls are commands that can be used with any device attached to SmartPort, as opposed to device-specific SmartPort calls. Generic SmartPort calls are described in detail in the following sections. Device- specific SmartPort calls are described later in this chapter. 214 Apple lie Technical Reference Status ($00) Description The Status call returns information about a particular device or about the SmartPort itself. Only Status calls that return general information are listed here. Some devices recognize other Status calls that provide diagnostic or other information specific to that device. Device-specific Status calls must be implemented with a status code of $04 or greater. On return from a Status call, the X and Y registers contain a count of the number of bytes transferred to the host. The X register contains the low byte of the count, and the Y register contains the high byte of the count. Parameter list Parameter count Unit number Status list pointer (low byte) Status list pointer (high byte) Status code Parameter descriptions Parameter count: Byte value = $03 Unit number: 1-byte value in the range $00 to $7E SmartPort assigns a unique number to each device at initialization time, as described in the section "SmartPort Assignment of Unit Numbers," earlier in this chapter. A Status call with a unit number of $00 and a status code of $00 returns the status of the SmartPort itself, as described under "SmartPort Status," later in this call description. CHAPTER 8 Block Device 1/0 215 Status list pointer: 2-byte pointer This parameter is a pointer to the buffer to which the status list is to be returned. The length of the buffer varies, depending on the status request being made. Status code: 1-byte value in the range $00 to $FF This number indicates the kind of status request being made. All devices respond to the following requests: Status code Status returned $00 Return device status $01 Return device control block $02 Return newline status (character devices only) $03 Return device information block Although devices must respond to the preceding status requests, a device may not be able to support the request. In this case, the device returns an invalid status code error ($21). Device-specific status codes are described in the section "Device-Specific SmartPort Calls," later in this chapter. Status code - $00 If the status code is $00, the device returns the device status block (DSB). The DSB consists of 4 bytes. The first is the genera! status byte: 216 Apple lie Technical Reference Bit Function 7 1 = block device; 0 = character device 6 1 = write allowed 5 1 = read allowed 4 1 = device on line or disk in drive 3 1 = format allowed 2 1 = media write-protected (block devices only) 1 Reserved; must = 0 0 1 = device currently open (character devices only) If the device is a block device, the next 3 bytes indicate the number of blocks in the device. The least significant byte is first. If the device is a character device, these bytes are set to 0. Note: There are currently no character devices available for use on SmartPort. Status code - $01 If the status code is $01, the device returns the device control block (DCB). The size and contents of the DCB are device dependent. The DCB is typically used to control various operating characteristics of a device. Each device has a default DCB, which you can alter with a Control call. The first byte of the DCB (the count byte) indicates the number of bytes in the DCB, excluding the count byte. A count-byte value of $00 indicates a DCB length of 256. The length of the DCB is always in the range 1 to 256 bytes, excluding the count byte. A UniDisk 3-5 The UniDisk 3.5 disk drive has no DCB, and returns an error (BadCtl $21) in response to a Status call with status code equal to $01. A Status code - $02 No character devices are currently implemented for use on the SmartPort, so the newline status is presently undefined. CHAPTER 8 Block Device 1/0 217 Status code - $03 If the status code is $03, the device returns the device information block (DIB). The DIB contains information identifying the device, indicating the type of device, and specifying various other attributes. The returned status list has the following form: Byte Function 1 Device status (1 byte) 2 Block size (low byte) 3 Block size (middle byte) 4 Block size (high byte) 5 ID string length in bytes (1 byte, $10 is maximum value) 6-21 ID siring (16 bytes) 22 Device type (1 byte) 23 Device subtype (1 byte) 24-25 Firmware version (2 bytes) The uses of these fields are as follows: • The device status byte is the same as the general status byte returned in the DSB (status code = $00). • The block size field is the same as the block size field returned in the DSB. • The ID string consists of a count byte indicating the number of ASCII characters in the ID string, followed by a 16-byte field containing an ASCII string identifying the device. The most significant bit of each ASCII character is set to 0. If the ASCII string consists of fewer than 16 characters, ASCII space characters ($20) are used to fill the unused portion of the string. 218 Apple He Technical Reference The device type and device subtype fields are 1-byte fields. Certain devices have been assigned types and subtypes, as follows: Type Subtype Device SCO SCO Apple II memory expansion card $01 $00 UniDisk 3.5 SOI $40 Apple 3.5 drive $02 ProFile™ hard disk $03409 Reserved $0A 5.25-inch disk $0B-$0F Reserved A Apple lie Plus In some cases, the Apple He Plus computer might return a subtype of $00 for an Apple 3.5 drive. To determine whether a device with a type of $01 and a subtype of $00 is a UniDisk 3.5 or an Apple 3.5 disk drive, issue a Status call with a status code of $05 to the device. This device-specific status call returns the UniDisk status if the drive is a UniDisk 3.5. If the device is an Apple 3.5 disk drive, it will return an invalid status code error ($21). A The 3 most significant bits in the DIB device-subtype byte indicate whether a device supports the extended SmartPort interface, disk-switched errors, or removable media, as follows: Bit Function 7 1 = supports extended SmartPort interface 6 1 = provides error if disk has been switched 5 0 = removable media 4-0 Reserved • Note: The Apple lie memory expansion card does not follow the subtype convention in that the memory expansion card has a subtype of $00, but does not have removable media. CHAPTER 8 Block Device 1/0 219 • The firmware version is a 2-byte number indicating the version of the firmware in the device. SmartPort A Status call with a unit number of $00 and a status code of $00 is a request to return the status status of the SmartPort driver. The status list is 8 bytes long. The first byte indicates the total number of devices connected to the port; the other 7 bytes are reserved. For port 4 in the Apple He Plus and in the memory expansion Apple lie with the ROM revision (ID byte SFBBF is $04), the first byte of the SmartPort status list is $00 if no memory expansion card is installed and $01 if a memory expansion card is present. In the memory expansion Apple He without the ROM revision (ID byte $FBBF is $03), the first byte of the SmartPort status list is S01 whether the memory expansion card is installed or not. Possible errors The following error values can be returned by the Status call: $06 BusErr Communications error $21 BadCtl Invalid status code $30-$3F; S50-S7F Device-specific error 220 Apple He Technical Reference ReadBlock ($01) Description The ReadBlock call reads one 512-byte block from the block device specified by the unit number. The block is read into memory starting at the address specified by the data buffer pointer passed in the parameter list. Parameter list Parameter count Unit number Data buffer pointer (low byte) Data buffer pointer (high byte) Block number (low byte) Block number (middle byte) Block number (high byte) Parameter descriptions Parameter count: Byte value = $03 Unit number: 1-byte value in the range $01 to $7E SmartPort assigns a unique number to each device at initialization time, as described in the section "SmartPort Assignment of Unit Numbers,'' earlier in this chapter. Data buffer pointer: 2-byte pointer This parameter is a pointer to the beginning of the buffer into which the data is to be read. The buffer must be 512 bytes long. CHAPTER 8 Block Device I/O 221 Block number: 3-bvte number The block number is the logical address in the device of a block of data to be read. There is no general connection between block numbers and the layout of tracks and sectors on the disk. Translation from logical to physical address is performed by the device. Possible errors The following error values can be returned by the ReadBlock call: $06 BusErr Communications error $27 IOError I/O error $28 NoDrive No device connected $2D BadBlock Invalid block number $2F Offline Device off line or no disk in drive 222 Apple He Technical Reference WriteBlock ($02) Description The WriteBlock call writes one 512-byte block to the block device specified by the unit number. The block is written from memory starting at the address specified by the data buffer pointer passed in the parameter list. Parameter list Parameter count Unit number Data buffer pointer (low byte) Data buffer pointer (high byte) Block number (low byte) Block number (middle byte) Block number (high byte) Parameter descriptions Parameter count: Byte value = $03 Unit number: 1-byte value in the range $01 to $7E SmartPort assigns a unique number to each device at initialization time, as described in the section "SmartPort Assignment of Unit Numbers," earlier in this chapter. Data buffer pointer: 2-byte pointer The data buffer pointer points to a buffer in memory that contains the data that is to be written to the device. The buffer must be 512 bytes long. CHAPTER 8 Block Device I/O 223 Block number: 3-byte number The block number is the logical address in the device of a block of data to be written. There is no general connection between block numbers and the layout of tracks and sectors on the disk. The translation from logical to physical address is performed by the device. Possible errors The following error values can be returned by the WriteBlock call: $06 BusErr Communications error $27 IOError I/O error $28 NoDrive No device connected $2B NoWrite Disk write-protected $2D BadBlock Invalid block number $2F Offline Device off line or no disk in drive 224 Apple lie Technical Reference Format ($03) Description The Format call formats a block device. The formatting performed by this call is not linked to any operating system; it only prepares all blocks on the medium for reading and writing. Operating-system-specific catalog information, such as bit maps and directories, are not prepared by this call. Parameter list Parameter count Unit number Implementation Some block devices may require device-specific information at format time. This device- of the Format specific information may include a list of bad blocks (referred to as a spare list) to be call written following physical formatting of the medium. In this case, it may not be desirable to implement the Format call so that a physical format is actually performed because the spare list might exist only in the device (that is, a backup spare list may not be available from the vendor), or because of the time involved in executing a bad-block scan. It may be more desirable to implement device-specific Control calls to lay down the physical tracks and to initialize the spare list. If this latter procedure is followed, the device driver need only return to the application with the A register set to $00 and the carry flag cleared in response to a format request. This procedure should be used only when it is not desirable to physically format the medium. Parameter descriptions Parameter count: Byte value = $01 Unit number: Byte value in the range $01 to $7E SmartPort assigns a unique number to each device at initialization time, as described in the section "SmartPort Assignment of Unit Numbers," earlier in this chapter. CHAPTER 8 Block Device I/O 225 Possible errors The followingerror values can be returned by the Format call: $06 BusErr Communications error $27 IOError I/O error $28 NoDrive No device connected $2B NoWrite Disk write-protected $2F OffLine Device off line or no disk in drive 226 Apple lie Technical Reference Control ($04) Description The Control call sends control information to the device. The information may be either general or device specific. Parameter list Parameter count Unit number Control list pointer (low byte) Control list pointer (high byte) Control code Parameter descriptions Parameter count: Byte value = $03 Unit number: 1-byte value in the range $00 to $7E SmartPort assigns a unique number to each device at initialization time, as described in the section "SmartPort Assignment of Unit Numbers," earlier in this chapter. Control list pointer: Word pointer (bank $00) This parameter is a pointer to the buffer from which the control information is to be read. The first 2 bytes of the control list (the count bytes, low byte first) specify the length of the control list (not including the count bytes). A control list is mandatory, even if the call being issued does not pass information in the list. In this latter case, the count bytes are equal to $00. CHAPTER 8 Block Device 1/0 227 Control code: 1-byte value in the range S00 to $FF The control code is the number of the control request being made. This number and the function indicated are device specific, except that all devices must reserve the following codes for the specific functions indicated: Control code Function $00 Resets the device $01 Sets device control block Control code - $00 If the control code is S00, the Control call performs a software reset of the device. It generally returns control parameters values to default values. A UniDisk 3-5 The UniDisk 3.5 disk drive does not respond to the Reset call. See the description of the Execute extension to the Control call in the section "SmartPort Calls Specific to UniDisk 3.5," later in this chapter, for a way to reset the UniDisk 3.5. A Control code - $01 If the control code is $01, the Control call alters the contents of the device control block (DCB). Devices generally use the bytes in this block to control global aspects of the device's operating environment. Because the length of the DCB is device dependent, the recommended way to set the DCB is to read in the DCB (with the Status call), alter the bits of interest, and then write the same string with the Control call. The first byte is the length of the DCB, excluding the byte itself. A value of $00 for the length byte indicates a DCB size of 256 bytes. A UniDisk 3.5 The UniDisk 3.5 disk drive has no DCB, and returns an error (BadCtl $21) in response to a Control call with control code equal to $01. A 228 Apple He Technical Reference Possible errors The following error values can be returned by the Control call: $06 BusErr Communications error $21 BadCtl Invalid control code $22 BadCtlParm Invalid parameter list $30-$3F Undefined Device-specific error CHAPTER 8 Block Device I/O 229 Init ($05) Description The Init call causes SmartPort to execute its initialization sequence, causing a hardware reset of all devices and assigning a unit number to each device. This call is not made to a specific unit; rather, it is made to the SmartPort as a whole. This call is executed automatically on system startup or forced cold reset. A Important The Init call must not be executed by an application designed to run on the Apple lies. Issuing this call on the Apple 1IGS may assign unit numbers to devices different from those in the ProDOS device list. Applications wishing to reset a sepcific device should use the Control call with a control code of $00. A Parameter list Parameter count Unit number Parameter descriptions Parameter count: Byte value = $01 Unit number: Byte value = $00 The unit number used in this call is always $00. This call must be made to the SmartPort itself; it cannot be made to an individual device. Possible errors The following error values can be returned by the SmartPort Init call: $06 BusErr Communications error $28 NoDrive No device connected 230 Apple lie Technical Reference Open ($06) Description The Open call prepares a character device for reading or writing. • Note: A block device does not accept this call, but returns an invalid command error ($01). There are currently no character devices implemented for use on SmartPort. Parameter list Parameter count Unit number Parameter descriptions Parameter count: Byte value = $01 Unit number: 1-byte value in the range $01 to $7E SmartPort assigns a unique number to each device at initialization time, as described in the section "SmartPort Assignment of Unit Numbers," earlier in this chapter. Possible errors The following error values can be returned by the Open call: $01 BadCmd Invalid command $06 BusErr Communications error $28 NoDrive No device connected CHAPTER 8 Block Device I/O 231 Close ($07) Description The Close call tells a character device that a sequence of read or write operations has ended. For a printer, this call could have the effect of flushing the print buffer. • Note-. A block device does not accept this call, but returns an invalid command error ($01). There are currently no character devices implemented for use on SmartPort. Parameter list Parameter count Unit number Parameter descriptions Parameter count: Byte value = $01 Unit number: 1-byte value in the range $01 to $7E SmartPort assigns a unique number to each device al initialization time, as described in the section "SmartPort Assignment of Unit Numbers," earlier in this chapter. Possible errors The following error values can be returned by the Close call: $01 BadCmd Invalid command $06 BusErr Communications error $28 NoDrive No device connected 232 Apple lie Technical Reference Read ($08) Description The Read call reads into memory the number of bytes specified by the byte count parameter. Although this call is generally intended for use by character devices, the Read call can be used to read a block of nonstandard size from a block device. In this latter case, the address pointer parameter is interpreted as a block address. Parameter list Parameter count Unit number Data buffer pointer (low byte) Data buffer pointer (high byte) Byte count (low byte) Byte count (high byte) Address pointer (low byte) Address pointer (middle byte) Address pointer (high byte) Parameter descriptions Parameter count: Byte value = $04 Unit number: 1-byte value in the range $01 to $7E SmartPort assigns a unique number to each device at initialization time, as described in the section "SmartPort Assignment of Unit Numbers," earlier in this chapter. Data buffer pointer: 2-byte pointer This parameter is a pointer to a buffer into which the data is to be read. The buffer must be large enough to accommodate the number of bytes requested. CHAPTER 8 Block Device I/O 233 Byte count: 2-byte number The byte count specifies the number of bytes to be transferred. Specific implementations of the SmartPort using the SmartPort Bus have limitations on this number; for example, for the UniDisk 3.5 you cannot transfer more than 767 bytes. For the memory expansion card and the Apple 3.5 disk drive, the byte count is limited to 512 bytes. A Apple He Plus In the Apple lie Plus computer, 512 bytes are transferred no matter what value you enter for the byte count, A Address pointer: 3-byte address The address pointer specifies the address within the device from which the bytes are to be read. The meaning of the address parameter depends on the device involved. This parameter can be used with a block device to specify a block address in order to read a block of nonstandard size. For example, the use of this parameter with the Read call makes it possible for an Apple 3.5 drive or UniDisk 35 drive to read 524-byte Macintosh blocks from 3.5-inch disks. Possible errors The following error values a n be returned by the Read call: $06 BusErr Communications error $27 IOError I/O error $28 NoDrive No device connected $2B NoWrite Disk write protected $2D BadBlock Invalid block number $2F Offline Device off line or no disk in drive 234 Apple He Technical Reference Write ($09) Description The Write call writes the number of bytes specified by the byte count to the device specified by the unit number. Although this call is generally intended for use by character devices, the Write call can be used to write a block of nonstandard size to a block device. In this latter case, the address pointer parameter is interpreted as a block address. Parameter list Parameter count Unit number Data buffer pointer (low byte) Data buffer pointer (high byte) Byte count (low byte) Byte count (high byte) Address pointer (low byte) Address pointer (middle byte) Address pointer (high byte) Parameter descriptions Parameter count: Byte value = $04 Unit number: 1-byte value in the range $01 to $7E SmartPort assigns a unique number to each device at initialization time, as described in the section "SmartPort Assignment of Unit Numbers," earlier in this chapter. Data buffer pointer: 2-byte pointer This parameter is a pointer to a buffer that contains the data to be written to the device. The buffer must be large enough to accommodate the number of bytes specified. CHAPTER 8 Block Device I/O 235 Byte count: 2-byte number The byte count specifies the number of bytes to be transferred. All of the current implementations of the SmartPort using the SmartPort Bus have a limitation of 767 bytes. Other peripheral cards supporting the SmartPort interface may not have this limitation. Address pointer: 3-byte address The address pointer specifies the address within the device to which the bytes are to be written. The meaning of the address parameter depends on the device involved. This parameter can be used with a block device to specify a block address in order to write a block of nonstandard size. For example, the use of this parameter with the Write call makes it possible for an Apple 35 drive or UniDisk 3.5 drive to write 524-byte Macintosh blocks to 3.5-inch disks. Possible errors The followingerror values can be returned by the Write call: $06 BusErr Communications error $27 IOError I/O error $28 NoDrive No device connected $2B NoWrite Disk write protected $2D BadBlock Invalid block number $2F Offline Device off line or no disk in drive 236 Apple lie Technical Reference Device-specific SmartPort calls In addition to the common command set of SmartPort calls already listed, a device may recognize its own device-specific calls. Usually, these calls arc implemented as a subset of the SmartPort Status or Control calls rather than as new commands. The following sections describe device-specific SmartPort calls for Apple 3.5 disk drives and UniDisk 3.5 disk drives. SmartPort calls specific to the Apple 3-5 disk drive One device-specific call is provided as an extension to the Control call for the Apple 3.5 drive. This device-specific control call may be used only with the Apple 3.5 drive. To determine whether a device is an Apple 3.5 drive, address a Status call with a status code of $03 to the device. If it is an Apple 3.5 drive, the device returns a type of $01 and a subtype of either $00 or $40. If it returns a subtype of $00, address a Status call with a status code of $05 to the device. If it returns an invalid status code error ($21), then it is an Apple 3.5 disk drive. Because this device-specific call to the Apple 3.5 drive is implemented as an extension to the Control call, only the control code and control list for this call are described here. Refer to the section on the Control call earlier in this chapter for information about the command byte and parameter list. The Apple 3.5 disk drive extension to the Control call is as follows: Control code Name Function $04 Eject Ejects a disk • Note There are several device-specific SmartPort calls for the Apple 3.5 disk drive available on the Apple lies in addition to the one implemented on the Apple lie Plus. For descriptions of these calls, see the chapter on SmartPort in the Apple IIGS Firmware Reference. CHAPTER 8 Block Device I/O 237 Eject The Eject extension to the Control call ejects a disk from the disk drive. Control code The control code for the Apple 3.5 disk drive Eject extension to the Control call is $04. Control list The control list for this call has a length of $0000. SmartPort calls specific to UniDisk 3.5 Five UniDisk 3.5 device-specific calls are provided as extensions to the Control and Status calls. These device- specific calls may be used only with the UniDisk 3.5. To determine whether a device is a UniDisk 35 drive, address a Status call with a status code of $03 to the device. If it is a UniDisk 3.5 drive, the device returns a type of $01 and a subtype of $00. A Apple He Plus In some cases, the Apple lie Plus computer may return a type of $01 and a subtype of $00 for an Apple 3.5 drive. To determine whether a device with a type of $01 and a subtype of $00 is a UniDisk 3.5 or an Apple 3.5 disk drive, issue a Status call with a status code of $05 to the device. If the device is an Apple 3.5 disk drive, it will return an invalid status code error ($21). A For calls implemented as extensions to the Control call, only the control code and control list are described in this section. For calls implemented as extensions to the Status call, only the status code and status list are described. Refer to the sections on the Control and Status calls earlier in this chapter for more information about these calls. 238 Apple lie Technical Reference The UniDisk 3.5 disk drive extensions to the Control call are as follows: Control code Name Function $04 Eject Ejects a disk $05 Execute Executes a 65C02 routine $06 Self Address Sets an address in the UniDisk 3.5 to which to download a 65C02 routine $07 Download Downloads a 65C02 routine into the UniDisk 3.5 The UniDisk 3.5 disk drive extension to the Status call is as follows: Status code Name Status returned $05 UniDiskStat Returns UniDisk 3.5 status Eject The Eject extension to the Control call ejects a disk from the disk drive. Control code The control code for the UniDisk 3.5 Eject extension to the Control call is $04. Control list The control list for this call has a length of $0000. Execute The Execute extension to the Control call causes the intelligent controller in the UniDisk 35 disk drive to execute a 65C02 subroutine. The register setup is passed from the control list of this call to the routine to be executed. The address in the UniDisk 3.5 address space to which the routine is loaded is set with the SetAddress extension to the Control call. The 65C02 routine to be executed is downloaded with the DownLoad extension to the Control call. CHAPTER 8 Block Device 1/0 239 Control code The control code for the UniDisk 3.5 Execute extension to the Control call is $05. Control list You use the control list for this call to set the initial 65C02 register setup for the routine to be executed. Count low byte $06 Count high byte $00 Accumulator value $xx X register value $xx Y register value $xx Processor Status value $xx Low program counter $xx High program counter $xx To reset the UniDisk 3.5 disk drive, use the Execute extension to the Control call with the program counter set to $E7A9. Doing so executes the UniDisk 3.5 disk drive's internal reset routine. SetAddress The SetAddress extension to the Control call sets the address in the UniDisk 3.5 controller memory space into which the DownLoad call loads a 65C02 routine. This address must point to free space in the UniDisk 3.5 memory map. The UniDisk 3.5 disk drive has free memory space from $0500 to $05FF, and has free zero page space from $00C0 to $00FF. Control code The control code for the UniDisk 3.5 SetAddress extension to the Control call is $06. 240 Apple He Technical Reference Control list You use the control list for this call to set the starting address for the routine to be executed as follows: Count low byte $02 Count high byte $00 Low byte address Sxx High byte address $xx Download The Download extension to the Control call downloads an executable 65C02 routine into the memory of the UniDisk 3.5 controller. The starting address to which the routine is loaded is set by the SetAddress extension to the Control call. The routine is executed by the Execute extension to the Control call. Control code The control code for the UniDisk 3.5 Download extension to the Control call is $07. Control list You use the control list for this call to list the 65C02 routine to be executed by the UniDisk 3.5 controller. The count field must be set to the length of the 65C02 routine to be downloaded. The control list is as follows: Count low byte $xx Count high byte $xx Executable 65C02 routine UniDiskStat The UniDiskStat extension to the Status call allows an application to get more information about an error that occurs during a UniDisk 3.5 read or write operation. It also allows an application to read the 65C02 register state after the UniDisk 3.5 controller executes a 65C02 routine. CHAPTER 8 Block Device I/O 241 For more information about memory-mapped I/O addresses internal to the UniDisk 3.5 controller, see the SmartPort chapter in the Apple IIGS Firmware Reference. Status code The status code for the UniDisk 3.5 UniDiskStat extension to the Status call is $05. Status list The status list returned by this call is as follows: Byte $00 Soft error $xx Retries $xx A register after execute $xx X register after execute $xx P register after execute $xx Byte $FF An example of a SmartPort call in a program The following text is an example of a SmartPort call in a program. 0000: 1 * 0000: 2 * This example shows how to find and use a SP interface. 0000: 3 * A search is made for a SP , and when one is found, a 0000: A * vector is set up that points to the SP entry. Then a 0000: 5 * Device Information Block (DIB) Status call is made, and 0000: 6 * if successful, the name string embedded in the DIB is 0000: 'I * output to the screen. Only the first device in the chain 0000: 8 * is accessed. 0000: 9 * 0000: 10 * 242 Apple He Technical Reference 0000 11 * Be sure to save any zero page locations that are in use 0000 12 * before you execute this routine, and remember to restore 0000 13 * them when you are done. 0000 14 * 0000 15 * 0000 16 MSB ON 0000 17 * 0000 18 * 0000 0006 19 ZPTempL equ S0006 ;Temporary zero 0000 20 * page storage 0000 0007 21 ZPTempH equ $0007 0000 22 * 0000 FDED 23 COut equ SFDED ^Console output 0000 FD8E 24 CROut equ SFD8E rCarriage return 0000 25 * 0000 0000 26 StatusCmd equ C 0000 27 * 0000 28 * 0300 0300 29 org S300 0300 30 * 0300 31 * Find a SmartPort in one of the 0300 32 * slots. 0300 33 * 0300 20 43 03 34 jsr FindSP 0303 BO IC 0321 35 bcs Error 0305 36 * 0305 37 * Now make the DIB call to the first guy 0305 38 * 0305 20 67 03 39 jsr Dispatch 0308 00 40 dfb StatusCmd 0309 6A 03 41 dw DParms 030B BO 14 0321 42 bcs Error 030D 43 * 030D 44 * Got the DIB; now print the name string 030D 45 * 030D A2 00 46 ldx #0 030F 030F 47 morechars equ * 030F BD 74 03 48 Ida DIBName,x 0312 09 80 49 ora #S80 ;C0ut wants high 0314 50 * Bit set 0314 51 * 0314 20 ED FD 52 jsr COut CHAPTER 8 Block Device I/O 243 0317:E8 53 inx 0318:EC 73 03 54 cpx DIBNameLen 031B:90 F2 0 3 OF 55 bit morechars 031D: 56 * 031D:20 8E ?D 57 jsr CROut /Finish it off 0320: 58 * with a return 0320: 59 * 0320:60 60 rts 0321: 61 * 0321: 62 * 0321: 0321 63 Error equ * 0321: 64 * 0321: 65 * There': either no SP around, cr there 0321: 66 » was no Unit l< 1 . . . give message 0321: 67 * 0321:A2 00 68 ldx #0 0323: 0323 69 errl equ * 0323:BD 2F 03 70 Ida Message,x 0326:F0 06 032E 71 beq errout 0328:20 sc FD 72 jsr COut 032B:E8 73 inx 032C.-D0 F5 0323 74 bne errl 032E: 75 * 032E: 032E 76 errcut equ * 032E:60 77 rts 032F: 78 * 032F:CE CF AO DO 7 9 Message asc 'NO SP OR NO DEVICE' 0341:8D OC 80 dfb $8D,0 0343: 81 * 0343: 82 * 0343: 0343 83 FindSP equ * 0343: 84 * 0343: 85 * Search slot 7 to slot 1 looking for 0343: 86 •wsignature by tes 0343: 87 * 0343:A2 07 88 ldx #7 ;Do for seven 0345: 89 X slots 0345:A9 C7 90 Ida #$C7 0347:85 07 91 sta ZPTempH 0349-.A9 00 92 Ida *soo 034B:85 06 93 sta ZPTempL 034D: 34 * 244 Apple lie Technical Reference 034D 034D 95 newslot equ * 034D A0 07 96 ldy #7 034F 97 034F 034F 98 again equ * 034F Bl 06 99 Ida (ZPTempL), y 0351 D9 70 03 100 cmp sigtab,y ;0ne of four 0354 101 * byte signature 0354 FO 07 035D 102 beq maybe ;Found one 0356 103 * signature byte 0356 C6 07 104 dec ZPTempH 0358 CA 105 dex 0359 DO F2 034D 106 bne newslot 035B 107 * 035B 108 * If we get here, it's because we couldn't 035B 109 * find a SmartPort. 035B 110 * Exit with the carry set. 035B 111 035B 38 112 sec 035C 60 113 rts 035D 114 035D 115 * If we get here, it means that one or 035D 116 * more of the signature bytes 035D 117 * for this card are what we're looking 035D 118 * for. Decrement the byte 035D 119 * counter and branch back to verify any 035D 120 * remaining bytes. 035D 121 035D 122 035D maybe equ 035D 123 88 dey 035E 124 dey ;If N=l then 035F 125 all sig bytes okay 035F 126 10 EE 034F bpl again 0361 127 0361 128 * Found a SmartPort interface. 0361 129 * Set up the call address. 0361 130 * We already have the high byte ($CN); 0361 131 * we just need the low byte. 0361 132 0361 133 0361 foundSP equ * 0361 134 0363 A9 FF 135 Ida #SFF 0365 85 06 136 sta ZPTempL AO 00 ldy #0 :For CHAPTER 8 Block Device I/O 245 0367 137 * i n d i r e c t load 0 3 6 7 Bl 06 138 Ida (ZPTempL),y ;Get t h e 0369 139 * byte 0369 140 0369 141 * Now the Ace has the low order ProDOS 0369 142 * entry point. The SP entry is 0369 143 * three locations past this... 0369 144 * 0369 IB 145 clc 036A 69 03 146 adc 13 0 3 6C B5 06 147 sta ZPTempL 036E 148 * 036E 149 * Now ZPTempL has the PC entry point. 036E 150 * Return with carry clear. 036E 151 * 036E 18 152 clc 036F 60 153 rts 0370 154 0370 155 0370 156 * These are the SP signature bytes in 0370 157 * their relative order. 0370 158 * The SFF bytes are filler bytes and 0370 159 * are not compared. 0370 160 0370 FF 20 FF 00 161 sigtab dfb $FF,$20,SFF,S00 0374 FF 03 FF 00 162 dfb SFF,$03,SFF,$00 0378 163 0378 164 0378 0378 165 Dispatch equ * 037B 6C 06 00 166 jmp (ZPTempL) /Simulate 037B 167 * an indirect JSR to SP 037B 168 037B 169 037B 037B 170 DParms equ * 0 3 7 B 03 171 DPParmCt dfb 3 ,-Status 037C 172 * calls have three parameters 0 3 7 C 01 173 DPUnit dfb 1 0 3 7 D 80 03 174 DPBuffer dw DIB 0 3 7F.03 175 DPStatCode dfb 3 0380 175 0380 177 0380 0380 178 DIB equ 246 Apple He Technical Reference 0380:00 179 DIBStatBytel dfb 0 0381:00 00 CO 180 DIBDevSize dfb 0,0,0 0384:00 181 DI3NameLen dfb 0 0385: 0010 182 DIBName ds 16,0 0395:00 183 DIBType dfb 0 0396:00 184 DIBSubType dfb 0 0397:00 00 185 DIBVersion dw 0 0399: 186 * 0399: 187 * Summary of commands and parameters Table 8-7 summarizes the command numbers and parameter lists for SmartPort calls. Table 8-7 Summary of standard commands and parameter lists Command Status ReadBlock WriteBlock Format Control Init Open Close Read Write CMDNUM $00 $01 $02 $03 $04 $05 $06 $07 $08 $09 CMDLIST byte 0 $03 $03 $03 $01 $03 $01 $01 $01 $04 $04 1 Unit Unit Unit Unit Unit Unit Unit Unit Unit Unit number number number number number number number number number number 2 Status Data Data Control Data Data list buffer buffer list buffer buffer pointer pointer pointer pointer pointer pointer 3 Status Data Data Control Data Data list buffer buffer list buffer buffer pointer pointer pointer pointer pointer pointer •1 Status Block Block Control Byte Byte code number number code couni count CHAPTER 8 Block Device 1/0 247 Table 8-7 Summary of standard commands and parameter lists (continued) Command Status ReadBlock WriteBlock Format Control Init Open Close Read Write 5 Block Block Byte Byte number number count count 6 Block Block ' number number 7 8 ' This parameter is device specific. • Note: The Read byte count and the Control call list contents must not be larger than 767 bytes. Upon return from the Read call, the byte count bytes contain the number of bytes actually read from the device. Summary of SmartPort error codes Following is a summary of error codes, including a brief description of the possible causes for each. If there is no error, the C flag (in the Status register of the microprocessor) is cleared (0), and the accumulator (the A register) contains O's. If the call was unsuccessful, the C flag is set (1), and the A register contains the error code. $00 No error. $01 BadCmd A nonexistent command was issued. Check the command number. $04 BadPCnt Bad call parameter count. The call parameter list was not properly constructed. Make sure the parameter list has the correct number of parameters. 248 Apple He Technical Reference r $06 BusErr A communications error between the device controller and the Apple He family member. Make sure that RAM is both read-enabled and write- enabled. Check the hardware (cables and connectors) between the device and the Apple lie family member. Check for noise sources; make sure the cable is properly shielded. $11 BadUnit Unit number $00 was used in a call other than Status, Control, or Init. $21 BadCtl The control code or status code is not supported by the device. $22 BadCtl Parm The Control parameter list contains invalid information. Make sure each value is within the range allowed for that parameter. $27 IOError The device encountered an I/O error when trying to read or write to the recording medium. Make sure that the medium in the device is formatted and not defective. Make sure the device is operating correctly. $28 NoDrive The device is not connected. This can occur if there is no device with the unit number specified. $2B NoWrite The medium in the device is write-protected. $2D BadBlock The block number is outside the range allowed for the medium in the device. This range depends on the type of device and the type of medium in the device (single-sided versus double-sided disk, for example). $2F Offline Device off line or no disk in drive. Check the cables and connections; make sure the medium is present in the drive, and that the drive is functioning correctly. $30-$3F DevSpec Errors that differ from device to device. See the technical manual for the device in question for details. $40-$4F Reserved Reserved for future expansion. $50-$7F NonFatal A device-specific soft error. The operation completed successfully, but some exception condition was detected. For details, see the technical manual for the device in question. CHAPTER 8 Block Device I/O 249 Chapter 9 Mouse and Game Input This chapter describes the mouse port and hand control (game) input capabilities of the Apple lie. The mouse and hand controls use the same 9-pin connector on the back panel; the firmware uses the port as directed by keyboard or program commands. • 251 A Important Mouse firmware entry points vary between versions of the Apple He. Thus, all port-dependent mouse addresses are given as SCnxx where n is the port number. Port numbers for the various versions of the Apple He are • Original and UniDisk 35 versions: n*4 • Memory expansion version and Apple He Plus: n=7 A Mouse input Table 9-1 summarizes the mouse port's characteristics and guides you to other information in this part of the chapter. • Warning If you want your programs that use the mouse on the Apple lie and other Apple II-series computers to work with the Apple He family, always use the I/O firmware entry points listed in Tables 9-3 and 9-4, rather than directly addressing the mouse hardware and RAM locations. • The mouse back panel connector is described in Chapter 11. Table 9-1 Mouse input port characteristics Port number original/UniDisk 3.5 port 4 memory expansion/Apple He Plus port 7 1 BASIC commands Turn on mouse : PRINT C H R $ ( 4 ) " P R # « " : P R I N T CHR$(1) Turn off mouse interrupts": PRINT "PR#n":PRINT CHR$(0) Turn on graphics character set: See "MouseText" in Chapter 6. 252 Apple He Technical Reference Table 9-1 Mouse input port characteristics (continued) Initial characteristics After a reset, all mouse interrupts are off and the rising edge of XO and YO are selected for interrupts. See "Mouse Input" in Chapter 11. Hardware page locations See Table 9-2. Monitor firmware routines None. I/O firmware entry points See Tables 9-3 and 9-4. Use of screen holes See Table 9-5. n is the port number of the mouse (4 or 7). Mouse connector signals The mouse uses the same DB-9 connector as the hand controls. However, the interpretation of the signals arriving on the pins differs depending on the commands and signals received. The connector pinout for the mouse port is given in Chapter 11. Mouse operating modes Your program should call the ServeMouse routine to determine the source of an interrupt as soon as it receives one in all the interrupt modes except transparent mode. Interrupts are discussed in Chapter 3. A Apple He There are some important differences between how the mouse works with the Apple He family computers and with an Apple lie with a mouse card. These differences are discussed in the section "Mouse Input" in Appendix D. A CHAPTER 9 Mouse and Game Input 253 Transparent mode In transparent mode, your program must read screen holes to check for mouse movement. An interrupt routine in the Apple lie—family firmware updates mouse position counters each time the mouse is moved, then returns control to the main program task. The findings of the interrupt routine are placed in the screen holes where your program can read them. Table 9-5 lists the screen holes with the information that your program should look for. This is the only mouse mode available to BASIC programs. Movement Intermpt mode Whenever the mouse moves, it sends a signal to the IOU, as described in the section "Mouse Input," in Chapter 11. The IOU sends an interrupt to the processor the next time a vertical blanking (VBL) signal occurs, and the processor executes the system intermpt handler routine. (In the Apple He family, the video circuitry generates a vertical blanking signal 60 times each second.) When movement interrupt mode is active, the system interrupt handler checks the mouse status bits (described in Table 9-2) for mouse movement. If the mouse has moved, the firmware updates the mouse-movement screen holes and then passes control to the user interrupt handler. (The location of the user intermpt handler is stored in the user interrupt vector at $03FE-S03FF.) The user interrupt handler can then update the cursor to its next screen position. Your intermpt handler must first call ServeMouse (described in Table 9-3) to see if the mouse caused the interrupt. It should then call ReadMouse to get the mouse status and its current X-Y position. Your interrupt handler can also change the mouse mode if you so desire. For example, you might want to change to a vertical- blanking-aclive mode so that your interrupt handler gets control 60 times every second. If your program initializes the mouse and sets bit 7 of the mouse port mode byte at $07FF ($07FC in the UniDisk 3.5 version) to 1, mouse movement interrupts are passed directly to the user intermpt handler. In this case, the firmware does not check the source of the interrupt, does not read the mouse status bits, and does not update the screen holes. VBL interrupts are still handled by the system interrupt handler. You should use this feature only if the mouse firmware can't keep up with your needs. You can use the SeLMouse routine described in Table 9-3 to set the mode byte. This feature is not available in the original Apple He. 254 Apple He Technical Reference Button Interrupt mode The Apple Ilc-family mouse-button hardware does not generate interrupts. However, in button interrupt mode, the system intermpt handler polls the mouse button every time a VBL signal occurs and passes control to the user intermpt handler if the mouse button has been pressed. Your intermpt handler must first call ServeMouse (Table 9-3) to see if the mouse button caused the interrupt. It should then call ReadMouse to get the mouse button status. Movement/button Interrupt mode The movement/button interrupt mode is a combination of the two modes just described. It provides the best response possible without constant polling of the mouse position and button. By using this mode, your program can effectively process a main task concurrently with cursor and menu updating. Vertlcal-blanklng-actlve modes When enabled by the EnVBl soft switch (Table 9-2), an IRQ interrupt is sent to the processor each time the VBL signal is asserted. When you select a vertical-blanking-active mouse mode, the firmware enables vertical blanking interrupts and the system intermpt handler passes control to the user interrupt handler each time a vertical blanking intermpt occurs. Each time a VBL interrupt occurs, the vertical blanking interrupt flag is set; you can read and reset this flag by using the RslVBl soft switch shown in Table 9-2. In all other respects (other than whether VBL interrupts are enabled and passed on to the user interrupt handler), the VBL-active mouse modes are identical to the VBL-inactive mouse modes. Mouse soft switches and status bits The soft switches assigned to the mouse interface are shown in Table 9-2. On power-up or reset, the hardware selects the rising edge of XO and YO (mouse movement signals) and masks out all mouse interrupts. This section tells what the mouse operating modes are for. Later sections of this chapter describe how to set the various mouse operating modes. CHAPTER 9 Mouse and Game Input 255 • Warning Table 9-2 is included here for your information only. You should use the built- in firmware to access the mouse. Writing your own mouse intermpt handler virtually assures that your program will not work with future versions of the Apple II. A Table 9-2 Mouse soft switches and status bits Name Action Hex Function IOUDis W $C07E On: Disable IOU access for addresses $C058 to $C05F; enable access to DHiRes switch' IOUDis w $C07F Off: Enable IOU access for addresses $0058 to $C05F; disable access to DHiRes switch* RdlOUDis R7 $C07E Read IOUDis switch (1 = off)t DisXY R/W $0058 Disable (mask) XO and Y0 movement interrupts:): EnbXY R/W $C059 Enable (allow) XO and Y0 movement interrupts:): RdXYMsk R7 $0040 Read status of XO/YO intermpt mask (1 = mask on) RstXY R $0048 Reset X0/Y0 interrupt flags XOEdge R/W $C05C Select rising edge of XO for interrupt} XOEdge R/W $C05D Select falling edge of XO for interrupt} RdXOEdge R7 $0042 Read status of XO edge selector (1 = falling) RstXInt R $C015 Reset mouse X0 intermpt flag YOEdge R/W $C05E Select rising edge of YO for interrupt! YOEdge R/W $C05F Select falling edge of YO for interrupt} RdYOEdge R7 $C043 Read status of YO edge selector (1 = falling) RstYInt R $0017 Reset mouse Y0 intermpt flag DisVBI R/W $C05A Disable (mask) VBL interrupts} EnVBl R/W $C05B Enable (allow) VBL interrupts} RdVBlMsk R7 $OMl Read status of VBL intermpt mask (1 = mask on) RstVBl R $C019 Read and then reset VBL intermpt flag PTrig R/W $0070 Reset VBIInt flag; trigger paddle timer RdBtnO R7 $0061 Read first mouse button status (1 = pressed)J Rd63 R7 $0063 Read second mouse button status (0 = pressed)*! 256 Apple He Technical Reference Table 9-2 Mouse soft switches and status bits (continued) Name Action Hex Function MouXl R7 $C066 Read status of XI (mouse X direction) (1 = high) MouYl R7 $0067 Read status of Yl (mouse Y direction) (1 = high) 1 When IOUDis is on, $C058-$CO5F do not affect mouse, and SC05E and SC05F become DHiRes (Table 6-9). t Read or write to $C07n also resets the VBL interrupt and triggers paddle timers. i These work only if IOUDis is off. 5 This location is also the Command key (Table 5-0- 'J This is also the location of the Shift-key mod (Appendix D). Software can select which edge of XO and YO information will cause the XInt or YInt. When an intermpt has occurred, you can read the direction of the mouse's XI movement by reading address SC066 bit 7, and Yl movement by reading address $C067 bit 7. A program can read the status of the soft switches by reading one of the locations $C040-$C043 and then testing data bit 7. The soft switches are described in Table 9-2. The section on mouse input in Chapter 11 explains what XO, YO, XI, Yl are and what they mean with respect to mouse movement. I/O firmware support for mouse input The Apple He family supports the mouse with firmware starting at address $CnOO. This firmware is necessary because the mouse requires fast, transparent interrupt processing to work effectively. CHAPTER 9 Mouse and Game Input 257 In assembly language you can use direct firmware support for sophisticated mouse applications. To enable the mouse, first load a mode byte into the accumulator (and $Cn in X, $n0 in Y) and then do a JSR to the firmware routine called SetMouse (described in Table 9-3). Valid mode bytes are the following: $00 Turns mouse off $01 Sets transparent mode $03 Sets movement intermpt mod $05 Sets button intermpt mode $07 Sets movement or button intermpt mode $08 Turns mouse off, VBlInt active $09 Sets transparent mode, VBlInt active $0B Sets movement intermpt mode, VBlInt active $0D Sets button interrupt mode, VBlInt active $0F Sets movement or button intermpt mode, VBlInt active The firmware then initializes the mouse. To read the current position and status of the mouse, first load $Cn into the X register, load $n0 into the Y register, save processor status, disable interrupts, and then perform a JSR to the firmware routine called ReadMouse (described in Table 9-3), which stores the information in the port n screen holes (listed in Table 9-5). Table 9-3 lists the locations at which you can read the offsets of the mouse port firmware routines. Each offset in Table 9-3 contains the low byte of the entry point of the routine described. The high byte of the routine is $Cn. The calling setup for all routines (except ServeMouse) is the same: the X register must contain $Cn, and the Y register must contain $n0. When the routine has finished, the A, X, and Y register contents are undefined. • Note: The mouse port firmware routines in the Apple lie and Apple He Plus computers do not require that specific values be set in the X and Y registers; however, you should always follow these directions to maintain compatibility with other Apple II family computers and with future versions of the Apple He. 258 Apple He Technical Reference Table 9-3 Offsets for pointers to Mouse firmware routines Offset from Routine Description SCnOO- $12 SetMouse Sets the mouse mode to the value in the accumulator. Input: A register contains mode (see $07Fx, Table 9-5) Output: Carry bit = 0 means mode was legal; carry bit = 1 means mode was not legal. $13 ServeMouse Services mouse interrupt if needed. Input: X, Y, A registers—doesn't matter. Output: Carry bit = 0 means mouse caused the intermpt; carry bit = 1 means something else caused it. This routine updates $077x to show which event caused the interrupt (see Table 9-5). $14 ReadMouse Updates screen holes to show current mouse X-Y position and button status; clears VBlInt, button and movement intermpt bits in the status byte. Doesn't reenable interrupts until after retrieving position values. Output: Carry bit = 0. $15 ClearMouse Sets the mouse position to 0, though not necessarily within clamping boundaries; leaves button and intermpt bits in status byte unchanged. Output: Carry bit = 0. $16 PosMouse Sets the mouse coordinates to new values. Input: X and Y screen holes contain new X and Y positions. Output: Carry bit • 0. $17 ClampMouse Sets new clamping boundaries (see Table 9-5). Does not affect mouse position or update mouse position screen holes; use ReadMouse to do that. Input: A register = 0 means set new X boundaries; A register = 1 means set new Y boundaries. Output: Carry bit = 0. $18 HomeMouse Sets the internal mouse position to the upper-left corner of the clamping window. Does not update mouse position screen holes; use ReadMouse to do that. $19 InitMouse Sets startup internal values; does not update mouse-position screen holes. Output: Carry bit = 0. 1 The value located at this offset is the low byte of the address of the routine. The high byte is C n. lVoie- n • 4 for the original Apple He and the UniDisk 35 Apple lie-, n • 7 for the memory expansion Apple lie and the Apple lie Plus. CHAPTER 9 Mouse and Game Input 259 Here is a sample sequence of events and calls: 1. Four screen holes contain the mouse's X and Y coordinates, and one contains the status of the last mouse movement (see Table 9-5). 2 Call InitMouse. 3. Inhibit interrupts, set up the boundaries you want, then call ClampMouse. 4. Use PosMouse, HomeMouse, or ClearMouse to position the mouse where you want it. 5. Put the mouse mode (see address S07Fx in Table 9-5) that you want to use in the accumulator, men call SetMouse. 6 If you have set one of the intermpt modes, then when an intermpt arrives, call ServeMouse to determine the source of the intermpt. 7. Disable interrupts and call ReadMouse. Retrieve the position values, then reenable interrupts. Pascal support Table 9-4 lists the locations and values of the I/O firmware protocol that Pascal 1.1 and later versions use. However, Pascal must use a special routine (called an attach driver) to support the mouse. • Table 9-4 Mouse port I/O firmware protocol for Pascal Address Value Description $Cn05 $38 Pascal ID byte $Cn07 $18 Pascal ID byte $CnOB $01 Generic signature byte of firmware cards $CnOC $20 2 = X-Y pointing device; 0 = identification code $CnOD Initialization routine (not implemented; returns error code) 1 $CnOE Standard read routine (not implemented; returns error code) $CnOF Standard write routine (not implemented; returns error code) $CnlO Standard status routine (not implemented; returns error code) $Cnll $0) Optional routines follow $CnFB $D6 A mouse identification byte 260 Apple He Technical Reference BASIC and assembly-language support In BASIC you must turn the mouse on by printing PR#« and then CHR$(1) before you can get input from the mouse. This sets transparent mode. After that, reenable video output with PR*3 and lake subsequent input from the mouse by issuing [N#«. The first input statement after that (INPUT X,Y,S) initializes and enables the mouse and returns a three-element string +xxxx,+yyyy,+st representing the x-coordinate, y-coordinate, and status digits. The coordinates will be integers between 0 and +1023. These are called the clamping boundaries ofthe mouse. The sign preceding the status digits is normally positive; it becomes negative when you press a key on the keyboard. The first digit, s, of the status is 0. The second digit, t, of the status is 1 if the mouse button is still pressed, 2 if it was just pressed, 3 if it was just released, and 4 if it is still released. To disable the mouse, use these statements: PRINT CHRSM) "PRtn" PRINT CHRS(O) PRINT CHRM) "PR*3" Screen holes Table 9-5 lists the screen holes that the mouse firmware uses. Note that the mouse firmware reserves port 5 screen holes for its own use. Also, the auxiliary page counterparts of the port 4 addresses are reserved for startup values. CHAPTER 9 Mouse and Game Input 261 Table 9-5 Mouse port screen hole locations Location Description Scratch area $0478 Low byte of clamping minimum $04F8 Low byte of clamping maximum $0578 High byte of clamping mimimum $05F8 High byte of clamping maximum Port 4 screen holes* $047x Low byte of X coordinate $04Fx Low byte of Y coordinate $057x High byte of X coordinate $05Fx High byte of Y coordinate $067x Reserved $06Fx Reserved $077x Status byte Bit 1 Equals 7 Button down 6 Button was down on last read and is still down 5 Movement since last read 4 Reserved 3 Interrupt from VBlInt 2 Interrupt from button 1 Intermpt from movement 0 Reserved $07Fx Mode byte (current mode; mask out bits 4-7 when testing) Bit 1 Equals 7 Use user intermpt handler (not available in original Apple He) 6-4 Reserved 3 VBlInt active 2 Intermpt on mouse button 1 Intermpt on mouse movement 0 Mouse active Port 5 screen holes Reserved * x is C for the original and UniDisk 3.5 versions of the Apple lie, and F for the memory expansion version and the Apple He Plus. 262 Apple He Technical Reference Using the mouse as a hand control You can use the mouse as if it were a set of hand controls or an X-Y pointing device. If you turn the mouse on, the Monitor hand control (game paddle) routines lake input from the mouse. This is possible because the mouse and the hand controls use the same back panel connector. You can mn a BASIC program that uses the Pdl function to read from the mouse by doing the following, either from the keyboard or from a program: 1. Start up the system with the BASIC program that uses paddles. 2 Type PR#n and press Return to turn on the mouse. The number n is 4 for the original and UniDisk 3.5 versions of the Apple He, and 7 for the memory expansion version and the Apple lie Plus. 3 Press Control-A Return to initialize the mouse. 4. Type PR# 0 and press Return to restore output to the screen. 5. Run the program. Play the game using the mouse instead of the paddles. A important Many copy-protected games do not work with a mouse. In addition, many games don't use built-in firmware for the paddles, A Game input The Apple He family supports game paddles, joysticks, and other hand controls connected to the DB-9 connector on its back panel. Table 9-6 is a summary of game input characteristics. CHAPTER 9 Mouse and Game Input 263 Table 9-6 Game input characteristics Port number None. Commands None. Initial characteristics Game inputs cannot be disabled. Hardware page locations $0061 Paddle 0 button, mouse button, and Command (1 = pressed). $0062 Paddle 1 button and Option key (1 = pressed). $0063 Mouse button (0 = pressed). $0064 Analog input (paddle) 0. $0065 Analog input (paddle) 1. $0070 Trigger paddle timer. Monitor firmware routine Location Name Description $FB1E PRead Reads a paddle position. I/O firmware entry points None. Use of screen holes None. The hand control connector signals Several inputs are available to programs or devices from the DB-9 connector on the back of each Apple He family member: two 1-bit inputs, or switches, and two analog inputs. The pinouts for the hand control connector are given in the section "Hand Control Input," in Chapter 11. When you connect a pair of hand controls to the 9-pin connector, the rotary controls use two analog inputs, and the pushbuttons use two 1-bit inputs. However, you can also use these inputs for many other jobs. For example, two analog inputs can be used with a two-axis joystick. 264 Apple He Technical Reference Switch inputs (SwO and Swl) The two 1-bit inputs can be connected to the output of another electronic device that meets the electrical requirements described in Chapter 11, or to a pushbutton. When you read a byte from one of these locations, only the high-order bit—bit 7—is valid information; the rest of the byte is undefined. From machine language, you can do a Branch Plus or Branch Minus on the state of bit 7. From BASIC, you can read the switch with a PEEK instmction and compare the value with 128. If the value is 128 or greater, the switch is on. The addresses for these switches are $C06l, SC062, and $C063 (decimal locations 49249 through 49251), as shown in Table 9-6. The lines from switch 0 and switch 1 (the buttons on the hand controls) are hard wired to the Command and Option keys (Open Apple and Closed Apple) on the keyboard. The switch 0 line is also connected to the mouse button. Location $C063 is a second address for the mouse button; this address is provided so that a program can distinguish a mouse button from the Command key. When the mouse button is pressed, SC063 (bit 7) goes from 1 to 0, and $C06l (bit 7) goes from 0 to 1. Analog inputs (PdlO and Pdll) The two analog inputs are designed for use with 150-Kfl variable resistors or potentiometers. The variable resistance is connected between the +5V supply and each input, so that it makes up part of a timing circuit. The circuit changes state when its time constant has elapsed, and the time constant varies as the resistance varies. Your program can measure this time by counting in a loop until the circuit changes state, or times out. A program must first reset the timing circuits before it can read the analog inputs. Accessing memory location SC070 does this. As soon as you reset the timing circuits, the high bits of the bytes at locations SC064 through SC067 are set to 1. If you use a PEEK instruction in BASIC to determine the values of locations 49252 through 49255, the values will be 128 or greater. Within about 3 milliseconds, these bits will change back to 0— byte values less than 128—and remain there until you reset the timing circuits again. The exact amount of lime each of the bits remains high is directly proportional to the resistance connected to the corresponding input. If these inputs are open—no resistances are connected—the corresponding bits may remain high indefinitely. CHAPTER 9 Mouse and Game Input 265 Monitor support for game input To read the analog inputs from machine language, you can use a program loop that resets the timers and then increments a counter until the bit at the appropriate memory location changes to 0, or you can use the built-in routine PRead. BASIC and other high-level languages also include convenient means of reading the analog inputs—refer to your language manuals. You can read and reread the same paddle at arbitrarily short intervals. However, you must wait at least 3 milliseconds between reading one paddle and reading a different paddle. The Monitor routine PRead (at address $FB1E) places in the Y register a number between $00 and $FF that represents the position of a hand control. You pass the number of the hand control in the X register. • Warning If the hand control number you furnish in the X register does not equal 0 or 1, strange things may happen. The paddle and vertical blanking both use SC070. Disable interrupts before calling PRead if you are reading the paddles and using VBL interrupts. A 266 Apple He Technical Reference Chapter 10 Using the Monitor The System Monitor is a set of subroutines in the Apple Ilc-family firmware that provides a standard interface to the built-in I/O devices. Many of the I/O subroutines described in Chapters 4 through 9 are part of the System Monitor. • 267 DOS, ProDOS, and the BASIC interpreters use Monitor subroutines by direct calls to their starting locations. You can call many of the standard subroutines from your programs in the same fashion. All of the standard firmware routines that Apple Computer, Inc., guarantees to maintain are described in Appendix F. You can perform most of the Monitor functions directly from the keyboard. This chapter tells you how to use the Monitor • to look at one or more memory locations • to change the contents of any location • to write small programs in machine language to be executed directly by the Apple lie family computer • to move and compare blocks of memory • to invoke other programs from the Monitor Invoking the Monitor The System Monitor starts at memory location $FF69 (-151). To invoke the Monitor, make a CALL -151 statement to this location from the keyboard or from a BASIC program. When the Monitor is running, its prompt character, an asterisk (*), appears on the left side of the display screen, followed by a cursor. To use the Monitor, type commands at the keyboard. When you have finished using the Monitor, you return to the BASIC language you were previously using by pressing Control-Reset, by pressing Control-C and then Return, or by typing 3D0G, which executes the resident program—usually Applesoft—whose address is stored in a jump instruction at location $03D0. A Important If ProDOS (or DOS) is connected via the standard I/O links (described in Chapter 4), you can issue commands to it from the Monitor. Under this arrangement, errors will return control to BASIC rather than to the Monitor, A 268 Apple He Technical Reference If you want to have Control-Reset return you to the Monitor, load the values $69, $FF, and $5A (decimal 105. 255, and 90) into the three locations starting at address S03F2 (decimal 1010, the reset-vector address, and the power- up byte). Syntax of Monitor commands To give a command to the Monitor, type a line on the keyboard, then press Return. The Monitor accepts the line using the standard I/O subroutine GetLn described in Chapter 4. A Monitor command can be up to 255 characters in length, ending with a carriage return. It can include three kinds of information: addresses, data values, and command characters. You type addresses and data values in hexadecimal notation. When the command you type calls for an address, the Monitor accepts any group of hexadecimal digits, if there are fewer than four digits in the group, it adds leading 0's; if there are more than four hexadecimal digits, the Monitor uses only the last four digits. It follows a similar procedure when the command syntax calls for two-digit data values. Each command you type consists of one command character, usually the first letter of the command name. The Monitor recognizes 22 different command characters. Some of them are punctuation marks, some are letters (uppercase or lowercase), and some are control characters. • Note: Although the Monitor recognizes and interprets control characters in an input line, they do not appear on the screen. This chapter contains examples of Monitor command use. Some of the data values displayed by your Apple Ilc-family computer may differ from the values printed in these examples, because they are variables stored in RAM. CHAPTER 10 Using the Monitor 269 Monitor memory commands When you use the Monitor to examine and change the contents of memory, it keeps track of the address of the last location whose value you inquired about and the address of the location that is next to have its value changed. These are called the last opened location and the next changeable tocation. • Warning Because locations $C0O0 through $C0FF contain special hardware circuits, issuing any command that reads or writes on this page can have unpredictable, and perhaps disastrous, results, A Examining memory contents When you type the address of a memory location and press Return, the Monitor responds with the address you typed, a dash, a space, and the value stored at that location, like this: *E000 E000- 4C *33 0033- AA * Each time the Monitor displays the value stored al a location, it saves that address as the last opened location and as the next changeable location. 270 Apple lie Technical Reference Memory dump When you type a period (.) followed by an address, and then press Return, the Monitor displays a memory dump: the data values stored at all the memory locations from the one following the last opened location to the location whose address you typed following the period. The Monitor saves the last location displayed as both the last opened location and the next changeable location. In these examples, the amount of data displayed by the Monitor depends on how much larger the address after the period is than the last opened location. *20 0020- 00 *.2B 0021- 28 00 18 OF 0C 00 00 0028- A8 06 DO 07 *300 0300- 99 *.315 0301- B9 00 08 0A 0A 0A 99 0308- 00 08 C8 DO F4 A6 2B A9 0310- 09 85 27 AD CC 03 *.32A 0316- 85 41 0318- 84 40 8A 4A 4A 4A 4A 09 0320- CO 85 3F A9 5D 85 3E 20 0328- 43 03 20 When the Monitor performs a memory dump, it starts at the address immediately following the last opened location and displays that address and the data value stored there. It then displays the values of successive locations up to and including the location whose address you typed, but only up to eight values on a line. When it reaches a location whose address is a multiple of 8—that is, one that ends with an 8 or a 0—it displays that address as the beginning of a new line, then continues displaying more values. After the Monitor has displayed the value at the location whose address you specified in the command, it stops the memory dump and sets that location as both the last opened location and the next changeable location. If the address specified on the input line is less than the address of the last opened location, the Monitor displays only the address and value of the location following the last opened location. CHAPTER 10 Using the Monitor 271 You can combine the two commands, opening a location and dumping memory, by concatenating them: type the first address, a period, and the second address. This combination of two addresses separated by a period is called a memory range. *300.32F 0300- 99 B9 00 08 0A 0A 0A 99 0308- 00 08 C8 DO F4 A6 2B A9 0310- 09 85 27 AD CC 03 85 41 0318- 84 40 8A 4A 4A 4A 4A 09 0320- CO 85 3F A9 5D 85 3E 20 0328- 43 03 20 46 03 A5 3D 4D *30.40 0030- AA 00 FF AA 05 C2 05 C2 0038- IB FD DO 03 3C 00 40 00 0040- 30 *E015.E025 E015- 4C ED FD E018- A9 20 C5 24 B0 0C A9 8D E020- A0 07 20 ED FD A9 * Pressing Return by itself makes the Monitor display one line of a memory dump; that is, a memory dump from the location following the last opened location to the next multiple-of-eight boundary. The Monitor saves the address of the last location displayed as both the last opened location and the next changeable location. *5 0 0 0 5 - 00 * Return 00 00 * Return 0008- 00 00 00 00 00 00 00 00 *32 0032- FF * Return AA 00 C2 05 C2 * Return 0038- IB FD DO 03 3C 00 3F 00 272 Apple He Technical Reference Changing memory contents The section on memory dumping showed you how to display values stored in the Apple lie family computer's memory; this section shows you how to change these values. You can change any location in RAM; you can change the characteristics and treatment of an output device by changing the contents of locations assigned to it; and you can change a soft switch setting by referencing its set and reset addresses. • Warning Use these commands carefully. If you change the zero-page locations used by the interpreter or operating system, you may lose programs or data stored in memory. A Changing one byte The previous commands keep track of the next changeable location; these commands make use of it. In the next example, which illustrates the Store ( : ) command, you open location 0, then type a colon followed by a r value. *0 0 0 0 0 - 4C * :5F The contents of the next changeable location have just been changed to the value you typed, as you can see by examining that location: *0 0 0 0 0 - 5F You can also combine opening and changing into one operation by typing an address followed by a colon and a value. In the next example, you type the address again to verify the change. *302:42 *302 0 3 0 2 - 42 CHAPTER 10 Using the Monitor 273 When you change the contents of a location, the value that was contained in that location is replaced by the new value, which will remain until you or some program replaces it with another value. • ASCII input mode: The Monitor has a tool to make entering values a little easier: ASCII input mode. ASCII input mode lets you enter ASCII characters as well as their hexadecimal ASCII equivalents. The Monitor uses the ASCII value of any character following an apostrophe; for example, 'A is the same as CI and 'B is the same as C2 to the Monitor. Therefore, to enter the string "Good morning!" at $0300 in memory, type *300:'G 'o *o ' d ' 'm ' o 'r 'n "i "n ' g '! Note that each character to be placed in memory is delimited by a leading and a trailing space. The only exception to this rule is that the last character in the line is followed by Return instead of a space. Changing consecutive locations You don't have to type a separate command with an address, a colon, and a value, and press Return for each location you want to change. You can change the values of up to 85 consecutive locations al a time—or even more, if you omil leading 0's from the values—by typing only the initial address and colon followed by all the values separated by spaces; end with Return. The Monitor stores the consecutive values in consecutive locations, starting at the location whose address you typed. After it has processed the string of values, it takes the location following the lasl changed location as the next changeable location. Thus, you can continue changing consecutive locations, without typing an address on the next input line, by typing another colon and more values. In these examples, you first change some locations, then examine them to verify the changes. * 3 0 0 : 6 9 01 20 ED FD 4C 03 *300 0 3 0 0 - 69 * Return 01 20 ED FD 4C 00 03 *10:0 1 2 3 *:4 5 6 7 *10.17 0010- 00 01 02 03 04 05 06 07 274 Apple He Technical Reference Moving data in memory You can copy a contiguous block of data from one area to another in RAM by using the Monitor's Move command. To move a range of memory, you must tell the Monitor both where the data is now situated in memory—the source locations—and where you want the copy to go—the destination locations. The format of the complete Move command looks like this: [destination] < [start] . [end] M The destination is the address where you want the first of the moved data to go. The less-than symbol (<) separates the destination address from the starting and ending addresses of the block of data to be moved. The period between two addresses is the Monitor's standard notation for specifying address ranges. If the second address in the source range specification is less than the first, only one value (that of the first location in the range) will be moved. When you type the actual command, replace the words in braces with hexadecimal addresses and omit the braces and spaces. Here are some examples of memory moves. First examine the values stored in one range of memory, then store several values in another range of memory. The actual Move commands end with M. *0.F 0000- 5F 00 05 07 00 00 00 00 0008- 00 00 00 00 00 00 00 00 *300:A9 8D 20 ED FD A9 45 20 DA FD 4C 00 03 *300.30C 0300- A9 8D 20 ED FD A9 45 20 0308- DA FD 4C 00 03 *0<300.30C M *0.C 0000- A9 8D 20 ED FD A9 45 20 0008- DA FD 4C 00 03 *310<8.A M *310.312 0310- DA FD 4C *2<7.9 M *0.C 0000- A9 8D 20 DA FD A9 45 20 0008- DA FD 4C 00 03 * CHAPTER 10 Using the Monitor 275 The Monitor moves a copy of the data stored in the source range of locations to the destination locations. The values in the source range are left undisturbed. The Monitor remembers the last location in the source range as the last opened location, and the first location in the source range as the next changeable location. If the destination address of the Move command is inside the source range of addresses, then strange things happen: the locations between the beginning of the source range and the destination address are treated as a subrange and the values in this subrange are replicated throughout the source range. Try it. Comparing data in memory You can use the Verify command to compare two ranges of memory using the same format you use to move a range of memory from one place to another. In fact, the Verify command can be used immediately after a Move command to make sure that the move was successful. The Verify command, like the Move command, needs a range and a destination. The syntax of the Verify command is (destination) < (start) . [end] V The Monitor compares the values in the source locations with the values in the locations beginning at the destination address. If any values don't match, the Monitor displays the address at which the discrepancy was found and the two values that differ. In the example, you store data values in the range of locations from 0 to SOD, copy them to locations starting al $0300 with the Move command, and then compare them using the Verify command. When you use the Verify command after you change the value at location 6 to $E4, the Monitor detects the change. *0:D7 F2 E9 F4 F4 E5 EE A0 E2 F9 A0 C3 C4 C5 *300<0.D M *300 ETIPAO"' (D0-7)_ RAM Main (DO-7) Video (VIDDO-7) g l (PAO-12) t T T Z Z " Tag RAM (A1-15) Addresses RAM Latch i ICTDQ-n . i n n r i(RA0-7) Video (D7) MMU k."< Address Bus *v Circuits {(RA0-7H Cache Glue (AO-15) (DO-7) / Auxiliary (ALTO-7) 80 Gate Array 80DIR // Man MMHMM RAM Latch Data Bus J(ALT0-7) (DO-7) f (VIDD7) |RA0-7) (VIDD6.7) TMG Video (RA14) Expansion Expansion Internal Connector (A2.3) Connector (A6) (D7) IOU AUD r^ Speaker •® (D7) External Audio Port GLU (DO-15) (AO.3-7) (DO-6) Keyboard DDannnnDaDDnnizi nDDDDaDDDDDngr Decoder •DnanaaaDDDQi cuaaqgDnDpnacn nnrnm IDDDDD (AO-2) Keyboard MUX Mouse and Hand Controller Port (AO.1,4) Serial Ports ACIA Channel 1 Port 1 / C * (DO-7) Drivers (Printer) and (AO.1,5) Channel 2 Receivers Port 2 ACIA (Modem) (D0-7J_ (DO-7) Internal Memory Floppy Disk Port External Expansion (DO-7) Floppy Disk Port (AO.1,4-15) Connector IWM (A1-3) (A5-7, 9-11) MIG (DO-7) RAMA5-10 jAO-4^ Disk Cache U-i CHAPTER 11 Hardware 303 Power supplies The electronic hardware of the Apple He family operates on DC voltages. These voltages are produced from standard household AC voltages (105-129 VAC). The AC voltage is called the line voltage, and the DC voltages arc called supply voltages. The original, UniDisk 35, and memory expansion versions of the Apple lie use an externa! transformer to rectify the AC line voltage into a 15 VDC input to the computer. This voltage is then converted by an internal voltage converter to the various supply voltages required by the main logic board, disk drive, and external devices. The main supply voltage is connected to the internal converter circuits by a power supply cord connected at the back panel. The Apple He Plus uses a completely internal, modular power supply. Line voltage is connected to the AC power input port at the back panel. If you purchased your Apple He outside the USA, consult Appendix E for its power supply characteristics. The Apple lie power supply The original, UniDisk 3.5, and memory expansion versions of the Apple lie use an external power transformer and an internal voltage converter. The Apple nc external transformer The transformer is a standard 1:8 step-down AC line transformer with a voltage rectifier circuit. AC line voltage is received on the primary side and stepped down to the secondary side. The stepped down AC voltage is then rectified and sent to the Apple He internal voltage converter through the power supply cord. The main supply voltage output is from 9 to 20 VDC. 304 Apple He Technical Reference The specifications of the external transformer are listed in Table 11-2. The line voltage must be in the range given in Table 11-2. A Warning The supply cord of the Apple lie external transformer must be plugged into a three-wire 115-volt (nominal) outlet. A two-wire outlet is not properly grounded—using it can result in damage to the external transformer and perhaps to the Apple He as well. If you are unable to insert the plug into the outlet, contact a licensed electrician to replace the outlet and, if necessary, install a grounding conductor. Do not defeat the purpose of the grounding plug. A Table 11-2 Apple lie power transformer specifications Line voltage 105 to 129 VAC, 60 Hz Maximum power consumption 25 W Supply voltage +15 VDC (nominal) Supply current 1.2 A (nominal) The external power connector The power supply cable is connected to the internal converter by means of a 7-pin DIN connector on the back panel. The connector pins are identified in Figure 11-3 and Table 11-3. CHAPTER 11 Hardware 305 Figure 11-3 Apple lie external power connector Table 11-3 Apple He external power connector signals Hn Signal Description 1,7 Not connected 2,3 Ground Common electrical ground 4 Chassis Chassis ground 5,6 +15V +15-volt DC input to converter The Apple lie internal voltage converter The internal voltage converter operates from the main supply voltage provided by the external power transformer. It provides DC supply voltages for all internal components and up to three external disk drives. The internal converter specifications are listed in Table 11-4. Negative 5 volts (-5 VDC) is derived on the main logic board itself from the -12 VDC supply . 306 Apple He Technical Reference Table 11-4 Apple !Ic internal voltage converter specifications Input voltage +9 to 20 VDC Maximum power consumplion 25 W Supply voltages +5V±5% + 12V ±10% -12V ±10% Maximum supply currents +5V: 1.5A +12V: 0.6 A continuous 0.9 A intermittent 1.5 A surge (for < 100 ms) -12V: 0.1 A (-5V: 50 mA) Maximum case temperature 60° C (140° F) The internal converter—called a switching-type converter—-works by using the DC voltage input to power a variable-frequency oscillator. The oscillator drives a small transformer with several separate windings to produce the various supply voltages. A circuit compares the voltage of the +5-volt supply with a reference voltage and feeds an error signal back to the oscillator circuit. The oscillator circuit uses the error signal to control the duty cycle of its oscillation and keep the supply voltages in their normal ranges. The converter includes circuitry to protect itself and the other electronic parts of the Apple He by limiting all three supply voltages whenever it detects one of the following malfunctions: • any supply voltage short-circuited to ground • any supply voltage outside the normal range Whenever one of these malfunctions occurs, the protection circuit varies the duty cycle of the oscillator, dropping all supply voltages to 0 if they cannot be brought back into their normal range. The Apple lie Internal power connector The internal converter is connected to the main logic board by means of a 44-pin card edge connector. The connector pins are identified in Figure 11-4 and Table 11-5. CHAPTER 11 Hardware 307 Figure 11-4 Apple lie internal power connector © © © ® © © © © © © © © © © © © © © © © © © © © © © © © © © © © © © © © © © © © © © © © 308 Apple He Technical Reference Table 11-5 Apple lie internal power connector signals Kn Signal Description 1-5 GND Ground 6 -12V -12-voll DC supply 7 GND Ground 8 -12V -12-voll DC supply 9 GND Ground 10 N.C. Not connected 11 GND Ground 12 FFF Switch ground/12V in 13 GND Ground 14 +12F IN +12VDCpowerin 15 GND Ground 16 +12F IN + 12V DC power in 17 GND Ground 18 +12F IN +12VDCpowerin 19 GND Ground 20 +12F IN +12VDCpowerin 21 GND Ground 22 +12FIN +12V DC power in 23-27 GND Ground 28 +5V +5V supply 29 GND Ground 30 +5V +5V supply 31 GND Ground 32 +5V +5V supply 33 GND Ground 34 +5V +5V supply 35 GND Ground 36 +12V + 12V supply 37 GND Ground 3 +12V +12V supply 39 GND Ground 40 +12V + 12V supply 41-44 GND Ground CHAPTER 11 Hardware 309 The Apple nc Plus internal power supply The Apple He Plus uses an internal switching-type power supply. Normal household AC line voltage is received on the primary side and stepped down and rectified to +5V, +12V, and -12 VDC on the secondary side. The power supply provides DC supply voltages for all internal components and up to three external disk drives. Negative 5 volts (-5 VDC) is derived on the main logic board itself from the -12 VDC supply by an R-C network. The basic specifications of the internal power supply are listed in Table 11-6. The line voltage must be in the range given in Table 11-6. • Warning The power supply cord of the Apple lie Plus must be plugged into a three- wire 115-volt (nominal) outlet. A two-wire outlet is not properly grounded— using it can result in damage to the power supply and perhaps to other components as well. If you are unable to insert the plug into the outlet, contact a licensed electrician to replace the outlet and, if necessary, install a grounding conductor. Do not defeat the purpose of the grounding plug, A • Table 11-6 Apple He Plus internal power supply specifications Line voltage 105 to 129 VAC, 60 Hz Maximum power output 20W Supply voltages +5V±5% +12V ±10% -12V ±10% Maximum supply currents +5V: 1.5A +12V: 0.6 A continuous 0.9 A intermittent 1.5 A surge (for < 100 ms) -12V: 0.1 A (-5V: 50 mA) Maximum case temperature 60° C (140° F) 310 Apple He Technical Reference The power supply includes circuitry to protect itself and the other electronic parts of the Apple He Plus by limiting all three supply voltages whenever it detects one of the following malfunctions: • any supply voltage short-circuited to ground • any supply voltage outside the normal range Whenever one of these malfunctions occurs, the protection circuit varies the duty cycle of the oscillator, draping all supply voltages to 0 if they cannot be brought back into their normal range. The internal power supply is connected to the main logic board by a 7-pin connector. The connector pins are shown in Figure 11-5 and Table 11-7. Notice that this connector differs from the one used in earlier Apple He computers, shown in Figure 11-4. • Figure 11-5 Apple lie Plus internal power connector © © © © © © © Table 11-7 Apple He Plus internal power connector signals Pin Signal Description 1 -12V -12-volt supply 2 +12V + 12-volt supply 3 +5V +5-volt supply 4 +5V +5-volt supply 5-7 GND Ground CHAPTER 11 Hardware 311 The 65C02 microprocessor The Apple He family uses a CMOS 6502 (designated as 65C02) microprocessor as its central processing unit (CPU). The 65C02 in the Apple lie runs at a clock rate of 1.023 MHz and performs up to 500,000 8-bit operations per second. The 65C02 in the Apple He Plus runs at a clock rate of either 1.023 MHz or 4 MHz and performs up to 2,000,000 8-bit operations per second. • Note: The clock rate is not a very good criterion for comparing different types of microprocessors. The 65C02 has a simpler instmction cycle than most other microprocessors and it uses instruction pipelining for faster processing. The speed of the 65C02 with a 1 MHz clock is equivalent to many other types of microprocessors with clock rates up to 5 MHz. In addition to requiring less power than earlier 6502 processors, the 65C02 in the Apple He family has 27 new instructions. However, programs that use these additional instmctions are not backward compatible with other Apple II computers not equipped with a 65C02. The manufacturer's data sheet for the 65C02 microprocessor is reproduced in Appendix A. 65C02 block diagram Figure 11-6 is a block diagram of the 65C02 microprocessor. Table 11-8 contains the general specifications of this chip. The 65C02 has a 16-bit address bus, giving it an address space of 64 KB. The Apple lie family uses special techniques to address a total of more than 64 KB (see Chapter 2). 312 Apple He Technical Reference Figure 11-6 65C02 block diagram; (copyright © 1982 by NCR Corporation; used by permission) Register Section Control Section F1ES IRQ NMI Aadress J Bus \ 4,lOu!t •I'^Out! CHAPTER 11 Hardware 313 Table 11-8 65C02 microprocessor specifications Type 65C02 Register complement 8-bit accumulator (A) 8-bit index registers (X,Y) 8-bit stack pointer (S) 8-bit Processor Status (P) 16-bit program counter (PC) Data bus 8 bits wide Address bus 16 bits wide Address range 65,536 (64 K) Interrupts IRQ signal (maskable) NMI signal (nonmaskable) BRK instmction (programmed) Operating voltage +5V(±5%) Power dissipation 5 mW (at 1 MHz) 65C02 timing The operation of the Apple He and Apple lie Plus computers is controlled by a set of synchronous timing signals, sometimes called dock signals. The Apple He and Apple lie Plus use a 14.318 MHz master liming signal, called I4M, to produce all the other timing signals. These timing signals perform two major tasks: controlling the computing functions, and generating the video display. In the Apple He family computers, the system timing signals PHO and PHI are generated by the timing generator IC, the TMG. The timing signals directly involved with the 65G02's operation are described in this section. Other timing signals are described in the section "The Timing Generator (TMG)," later in this chapter. The relationships of the main system timing signals are diagrammed in Figure 11-7, and the signals are listed in Table 11-9. The system clock signals PHO and PHI are complementary signals at a frequency of 1.023 MHz. The PHO signal is also connected to the clock input of the 65C02. Because the signal PHO is used in the Apple He family both as the 65C02 clock input and as the system clock, it is a bit early compared to the 02 system clock described in Appendix A. 314 Apple lie Technical Reference A Apple lie Plus In the Apple He Plus computer, the PHO clock signal is input to the CGGA, and the CGGA provides a separate clock to the 65C02. This arrangement allows the CGGA to operate the 65C02 at either 1.023 MHz or 4 MHz, as required. In addition, the 65C02 processor's address and data lines are connected to the CGGA; the CGGA provides the address and data signals for the rest of the system. In other words, the CGGA and the 65C02 together effectively constitute the CPU of the Apple He Plus computer. When the term CPU is used in the discussion of timing signals, you should understand it to mean the 65C02 processor in the Apple He, and the combination of the CGGA and the 65C02 in the Apple lie Plus. The CGGA is described in the section "The Apple lie Plus Cache Glue Gate Array (CGGA)," later in this chapter, A CHAPTER 11 Hardware 315 5 o en o 01 > § -o o i 5> E en o I O T hThT Table 11-9 System timing signal descriptions Signal Description 14M Master oscillator, 14.318 MI Iz; also 80-column dot clock VID7M Intermediate timing signal and 40-column dot clock Q5 Intermediate liming signal, 2.045 MHz with asymmetrical duly cycle PHO Phase 0 of system clock, 1.023 MHz; complement of PHI; clock inpul to CPU PHI Phase 1 of system clock, 1.023 MHz; complement of PHO The CPU's operations are related to the clock signals in a simple way: internal during PHI, external during PHO. The CPU puts an address on the address bus during PHI. This address is valid not later than 110 nanoseconds after PHI goes high and remains valid through all of PHO. The CPU reads or writes data during PHO. If the CPU is writing, the read/write signal is low during PHO and the CPU puts data on the data bus. The data are valid not later than 75 nanoseconds after PHO goes high. If the CPU is reading, the read/write signal remains high. Data on the data bus must be valid no later than 50 nanoseconds before the end of PHO. More information about the 65C02 and its instruction set is in Appendix A. The custom integrated circuits Most of the circuitry that controls memory and I/O addressing in the Apple He family computers is in five custom integrated circuits: • the memory management unit (MMU) • the input-output unit (IOU) • the timing generator (TMG) • the general logic unit (GLU) • the disk controller unit, also known as the Integrated Woz Machine (IWM) CHAPTER 11 Hardware 317 ^ The soft switches that control the various I/O and addressing modes of the Apple lie family are addressable flags inside the MMU, IOU, and GLU. The functions of the MMU and IOU are not as independent as their names suggest; working together, they generate all the addressing signals. For example, the MMU generates the RAM address signals for the CPU, while the IOU generates similar RAM address signals for the video display and most I/O hardware addresses. The Apple lie Plus computer has two additional integrated circuit chips: • the multidrive interface glue (MIG) • the cache glue gate array (CGGA) The MIG provides interface logic for disk drives. The CGGA allows the Apple He Plus to operate at a much faster speed than the other Apple He computers. The memory management unit (MMU) The circuitry inside the MMU implements these soft switches: • Page 2 display (Page2) (described in Chapter 6) • high-resolution mode (HiRes) (Chapter 6) • store to 80-column display (80Store) (Chapter 6) • select bank 2 (Bank2) (Chapter 2) • enable bank-switched RAM (EnlCRAM) (Chapter 2) • read auxiliary memory (RAMRd) (Chapter 2) • write auxiliary memory (RAMWrt) (Chapter 2) • auxiliary stack and zero page (AltZP) (Chapter 2) • reset mouse Y intermpt (RstYInt) (Chapter 9) • reset mouse X intermpt (RstXInt) (Chapter 9) These switches are available on MMU pin 21, which is connected to bit 7 on the data bus. Figure 11-8 shows the MMU pinouts; Table 11-10 describes the signals. 318 Apple lie Technical Reference Figure 11-8 MMU pinouts GND 1 ^ 40 Al AO 2 39 A2 PHO 3 38 A3 Q3 4 37 A4 PRAS' 5 36 A5 RAO 6 35 A6 RA1 7 34 A7 RA2 8 33 A8 RA3 9 32 A9 RA4 10 31 A10 RA5 11 30 A11 RA6 12 29 A12 RA7 13 28 A13 R/W 14 27 A14 INH" 15 26 A15 C06X* 16 25 + 5V EN80* 17 24 SELIO* KBD- 18 23 CASEN- ROMEN2' 19 22 C07X* ROMENT 20 21 MD7 A Important A signal name followed by an asterisk (PRAS*) is active low—that is, it is asserted when the signal is at a TTL low (OV) level, A The 64 KB dynamic RAMs used in the Apple lie family use a multiplexed address, as described later in this chapter. The MMU generates this multiplexed address for memory reading and writing by the 65C02 CPU. • Table 11-10 MMU signal descriptions Pin Signal Description 1 GND Power and signal common 2 AO System address input 3 PHO System clock, phase 0, input 4 03 Timing signal input 5 PRAS' Memory row-address strobe 6-13 RA0-RA7 Multiplexed address output 14 R/W' System read-write control signal 15 iNir Inhibits main memory use (tied high through a pullup resistor) CHAPTER 11 Hardware 319 Table 11-10 MMU signal descriptions (continued) Pin Signal Description 16 oofic Causes $C06x outputs to go to 0 during PHO 17 EN80* Enables auxiliary RAM 18 KBD* Enables keyboard data bits 0-6 19 R0MEN2* Enables ROM (tied to ROMENr) 20 ROMENr Enables ROM (tied to ROMEN2') 21 MD7 State of MMU flags on data bus bit 7 22 C07X' Causes $C07x outputs to go to 0 during PHO 23 CASEN' Enables main RAM 24 SELIO* Goes to 0 during PHO for any access to $00 page except SC08x, Bx, Cx, or Fx 25 +5V Power 26-40 A15-A1 System address input The input/output unit (IOU) Input/output unit (IOU) implements the soft switches and status bits that control the following features: • Page 2 display (Page2) (described in Chapter 2) • high-resolulion mode (HiRes) (Chapter 2) • text mode (TEXT) (Chapter 6) • mixed mode (MIXED) (Chapter 6) • 80-column display (8OC0I) (Chapter 6) • character-set select (AltChar) (Chapter 6) • any-key-down flag (AKD) (Chapter 5) • keyboard stroke (Chapter 5) • mouse movement interrupts (X0, Y0) (Chapter 9) • vertical blanking intermpt (VBlInt) (Chapter 9) 320 Apple He Technical Reference These switches are available on IOU pin 9, which is connected to bit 7 on the data bus. Figure 11-9 shows the IOU pinouts; Table 11-11 describes the signals. • Figure 11-9 IOU pinouts GND 1 ^ 40 HO GR 2 39 SYNC SEGA 3 38 WNDW SEGB 4 37 CLRGAT- VC 5 36 RA10' 80COL- 6 35 RA9- CASSO 7 34 VIDD6 SPKR 8 33 VIDD7 MD7 9 32 KSTRB YMOVE 10 31 AKD (N.C.) 11 30 IOUSELIC (N.C) 12 29 A6 PDLO/XMOVE 13 28 + 5V R/W 14 27 Q3 RESET- 15 26 PHO IRCT 16 25 PRAS- RAO 17 24 RA7 RA1 16 23 RA6 RA2 19 22 RA5 RA3 20 21 RA4 The dynamic RAMs used in the Apple He family require a multiplexed address, as described in the section "Dynamic RAM Refreshment" later in this chapter. The IOU generates this multiplexed address during clock phase 1 for the data transfers required for display and memory refresh. The way this address is generated is described under "The Video Counters," later in this chapter. • Table 11-11 IOU signal descriptions Pin Signal Description GND Power and signal common GR Graphics mode enable SEGA In text mode, works with VC (see pin 5) and SEGB to determine character row address SEGB In text mode, works with VC (see pin 5) and SEGA; in graphics mode, selects Hi-Res when low, Lo-Res when high VC Vertical counter bit: in text mode, SEGA, SEGB, and VC determine which of the eight rows of a character's dot pattern to display; in Lo-Res, selects upper or lower block defined by a byte 80COL' 80-column video enable CHAPTER 11 Hardware 321 Table 11-11 IOU signal descriptions (continued) Pin Signal Description RA14 ROM address 14, used for ROM bank switching; derived from Cassette Out signal (CASSO) 8 SPKR Speaker output signal 9 MD7 Internal IOU flags for data bus (bit 7) 10 YMOVE Detects mouse movement along Y axis 11 N.C. Not used 12 N.C. Not used 13 PDLO/XMOVE Detects mouse movement along X axis 14 R/W 65C02 read-write control signal 15 RESET* Power on and reset output 16 IRQ* Maskable intermpt line to 65C02 17-24 RA0-RA7 Video refresh multiplexed RAM address (phase I) 25 PRAS* Row-address strobe (phase 0) 26 PHO System clock, phase 0 27 <2 Intermediate timing signal 28 +5V Power 29 A6 System address bit 6 30 IOUSELIO' Derived from the SELIO* output for MMU pin 24 31 AKD Any-key-down signal 32 KSTRB Keyboard strobe signal 3334 VIDD7.VIDD6 Video display data bits 3536 RA9,,RA10' Video display control bits 37 CLRGAT Color-burst gate (enable) 38 WNDW Blanking signal for display 59 SYNC Synchronization signal for display 40 HO Horizontal timing signal for display (low bit of character counter) 322 Apple lie Technical Reference The timing generator (TMG) A custom timing generator chip (TMG) generates several timing and control signals in the Apple He family computers. The TMG pinouts are shown in Figure 11-10; the signals are listed in Table 11-12. For more information on system timing signals, see the section "65C02 Timing," earlier in this chapter. • Figure 11-10 TMG pinouts 14M 1 KJ 20 + 5V 7M 2 19 PRAS* CREF 3 18 (N.C.) HO 4 17 PCAS- VIDD7 5 16 Q3 SEGB 6 15 PHO TEXT 7 14 PH1 CASEN- 8 13 VID7M 80COL- 9 12 LDPS - GND 10 11 TMGEN - Table 11-12 TMG signal descriptions Pin Signal Description 1 14M 14.318 MHz master timing signal input 2 7M 7.159 MHz timing signal 3 CREF 3.5795 MHz color reference timing signal 4 HO Horizontal video timing signal 5 VIDD7 Video data bit 7 6 SEGB Video timing signal 7 TEXT Video display text-modes enable 8 CASEN* RAM enable (CAS enable) 9 80COL* Enables 80-column display mode 10 GND Power and signal common 11 TMGEN* Enables master timing 12 LDPS* Video shift-register load enable 13 VID7M Video dot clock enable, 7 MHz or continuous 0 14 PHI System clock, phase 1 15 PHO System clock, phase 0 16 03 Intermediate timing and strobe signal 17 PCAS* RAM column-address strobe 18 N.C. Reserved for testing 19 PRAS' RAM row-address strobe 20 +5V Power CHAPTER 11 Hardware 323 The general logic unit (GLU) The general logic unit is a single chip that contains the miscellaneous logic required for the system. It provides • all RAM read/write timing • Double Hi-Res enable/disable • soft-switch status registers • write command registers • IOU control for mouse interrupts • Double Hi-Res soft switches The GLU's pin assignments are shown in Figure 11-11 and its signals are listed in Table 11-13. • Figure 11-11 GLU pinouts 14M 1 ^ 24 + 5V AO 2 23 SER* A3 3 22 IOUHOLE A4 4 21 DISK' A5 5 20 7M A6 6 19 CREF A7 7 18 (N.C.) PHO 8 17 (N.C.) SELIO- 9 16 TEXT GR 10 15 R/W RESET- 11 14 MD7 GND 12 13 GLUEN- Table 11-13 GLU signal descriptions Hn Signal Description 1 14M Master clock (14.318 MHz) 2,3-7 A0A3-A7 Address lines to select least significant byte of addresses on CO page 8 PHO System clock, phase 0 9 SELIO* Device select for selecting most significant byte of the address 10 GR Graphics mode select line 324 Apple He Technical Reference Table 11-13 GLU signal descriptions (continued) Pin Signal Description 11 RESET* Master reset for system; resets GLU 12 GND Ground reference and negative supply 13 GLUEN* Enables GLU 14 MD7 Indicates status of MMU flags on data bus bit 7 15 R/W* Read/write qualifier input from processor 16 TEXT Video text signal from TMG; set to inverse of GR, except in Double Hi-Res mode 17,18 N.C. Not used 19 CREF Color reference signal 20 7M 7 MHz clock output 21 DISK* Disk controller device select output 22 IOUHOLE Controls IOUSELIO 23 SER* Serial controller device select output 24 +5V +5 volt supply The disk controller unit (IWM) The IWM is a disk controller chip that contains all of the circuitry necessary to provide a complete electrical interface for the 5.25- inch disk drives. Right after reset, the IWM is configured as an integrated group code recording (GCR) disk drive controller. It also has a status register, mode register, and multiple operating modes. It provides both synchronous and asynchronous modes, as well as a fast mode with a data rate twice that of normal disk I/O speeds. Figure 11-12 shows the IWM pin assignments; Table 11-14 describes the IWM signals. CHAPTER 11 Hardware 325 Figure 11-12 IWM pinouts SEEKPHO . ^ 28 SEEKPH1 SEEKPH2 2 27 SEEKPH3 AO 3 26 • 5V Al 4 25 Q3 A2 5 24 7M A3 6 23 RESET* DISK- 7 22 RDDATA WRDATA 8 21 WRPROT WRREQ- 9 20 DRV DO 10 19 DR2- D1 11 18 D7 D2. 12 17 D6 D3 13 16 D5 GND 14 15 D4 Table 11-14 IWM signal descriptions Hn Signal Description 1 SEEKPHO Disk drive register select line CAO, one of four programmable output lines 2 SEEKPH2 Disk drive register select line G\2 3 AO The data input to the state bit selected by Al to A3 4-6 A1-A3 These three inputs select one of the 8 bits in the state register to be updated DISK* Device enable; the falling edge of DISK' latches information on Al to A3. The rising edge of either Q3 or DISK* qualifies write register data 8 WRDATA The serial data output; each 1 bit causes a transition on this output 9 WRREQ* Programmable buffered output line 10-13 D0-D3 DO to D7 make up the bidirectional data bus 14 GND Ground reference and negative supply 15-18 D4-D7 The remaining bits of the bidirectional data bus 19 DR2* Drive 2 select 20 DR1* Drive 1 select 21 WRPROT Write-protect input; this can be polled via bit 7 of the status register 22 RDDATA Serial data input line; the IWM synchronizes the falling transition of each pulse 326 Apple He Technical Reference Table 11-14 IWM signal descriptions (continued) Pin Signal Description 23 RESET* IWM reset: places all IWM outputs in their inactive state and sets all state and mode register biLs to 0 24 7M 7 MHz clock input 25 03 A 2.0 MHz clock input used to qualify the timing of the serial data being written or read 26 +5V The +5 volt supply 27 SEEKPH3 Disk drive register write strobe LSTRB 33 SEEKPH1 Disk drive register select line CA1 The Apple Lie Plus multldrive interface glue (MIG) The MIG is actually two ICs: a custom integrated circuit (the Mc7 chip) and a 2 KB static RAM. The static RAM is used as a RAM buffer to support the high data rate of the 3.5-inch disk drives. The MIG chip provides the interface (the "glue logic") that implements the RAM buffer for the internal disk drive and some interface logic for other disk drives. Figure 11-13 shows the pin assignments for the MIG chip, and Table 11-15 describes the pin functions. • Figure 11-13 MIG chip pinouts IOSEL' 1 ^ 28 RAMA5 A5 2 27 RAMA6 A6 3 26 RAMA7 A7 4 25 VDD A9 5 24 RAMA8 A10 6 23 RAMA9 A11 7 22 RAMA10 BUSEN- 8 21 RAMEN- R/W 9 20 ROMEN 2* PH11 10 19 HDSEL EN2X- 11 18 3.5- VSS 12 17 ENB2' ROMEN 1' 13 16 INTEN* RESET' 14 15 IWMRES* CHAPTER 11 Hardware 327 Table 11-15 MIG chip signal descriptions Pin Signal Description 1 IOSEL' Tied to RESET* (pin 14) 2 A5 System address bit 5 3 A6 System address bit 6 4 A7 System address bit 7 5 A9 System address bit 9 6 A10 System address bit 10 7 All System address bit 11 8 BUSEN* Output that indicates valid access to MIG address space 9 R/W System read/write control line 10 PHI System clock 11 EN2X' Input thai indicates an access to address SCOnx is occurring, where n is $9 through $E; an access to SCOnx addresses port n-8 12 VSS Ground 13 ROMEN1* Input that indicates an access to lower ROM bank space $0100 through $DFFF is occurring 14 RESET System reset or ROM address 14 15 IWMRES* Latched output bit to reset IWM 16 INTEN* Latched output bit to enable internal drive 17 ENB2 Follows EN2X* or ROMENl* if addressing mapped device space to select external drives 18 3.5 DRIVE' Latched output bit to select 5.25-inch or 3.5-inch drives 19 HDSEL Latched output bit used for 3.5-inch drives 23 ROMEN2' ROM enable output line; follows ROMENl* 21 RAMEN* RAM enable output line to 2 KB RAM buffer 22 RAMA 10 RAM buffer address bit 10 23 RAMA9 RAM buffer address bit 9 24 RAMA8 RAM buffer address bit 8 25 VDD +5 VDC 2b RAMA7 RAM buffer address bit 7 27 RAMA6 RAM buffer address bit 6 28 RAMA5 RAM buffer address bit 5 328 Apple He Technical Reference The Apple lie Plus cache glue gate array (CGGA) Most computer programs mn the same routines repeatedly; therefore, a data cache, which allows fast access to the most recently used data, can often significantly enhance the speed of a system. In the Apple lie Plus computer, a data cache is combined with a 4 MHz 65C02 microprocessor, so thai frequently used data and code can be processed at 4 MHz instead of the 1.023 MHz processor speed of earlier Apple lie computers. The Apple He Plus accelerator circuit includes the Cache Glue Gate Array (CGGA), a 16 MHz crystal oscillator, and two 8 KB static RAM chips. As shown in the Apple lie Plus block diagram, Figure 11-2, the CGGA interfaces the cache RAM and 65C02 to the rest of the system. The CGGA provides a 4 MHz clock to the CPU. When the accelerator is enabled and the CPU is processing data from the cache RAM, the system runs at its fastest speed. When the CPU has to access memory from system RAM, or when the accelerator is disabled, the CGGA synchronizes the CPU to the rest of the system and the Apple He Plus mns at the same speed as other Apple He computers. The CGGA is programmed to keep track of which parts of the address space can be cached and which cannot. For example, when the Apple lie Plus is switched on or reset, ROM code for ports 1, 2, 5, and 6, and the code for the speaker and game paddles cannot be cached; this code is restricted to mn at 1.023 MHz. The code for ports 3, 4, and 7 can be cached, and so can mn at up to 4 MHz. The RAM cache consists of two 8 KB static RAM chips: one RAM for data and one for tags. For each byte of data in the data RAM there is a corresponding tag byte in the tag RAM. Because there is 128 KB of system memory in the Apple He Plus and only 8 KB of memory in the data cache, the tag RAM is used to indicate from which part of memory each byte of data came. The CGGA keeps track of which areas of bank-switched memory are switched in, and determines from the Lags whether the data in the data RAM corresponds to the address on the processor address bus. If the tag for a byte of data indicates that the byte is the one requested by the 65C02, the data is said to be valid When Ihe 65C02 initiates a data read operation by raising its R/W line, the CGGA checks the tag RAM to determine if the data in the RAM cache is valid. If the data is valid and the accelerator is enabled, the CGGA provides a 4 MHz clock to the 65C02 and puts the data from the RAM cache on the processor data bus. If, however, the CGGA determines thai the data in the RAM cache is not valid, the CGGA provides a 1.023 MHz clock to the 65C02, places the address of the data on the system address bus, and reads the data from system RAM. The CGGA then returns the data from memory to the 65C02, updates the data cache with the same data, and updates the tag cache. CHAPTER 11 Hardware 329 When the 65C02 writes data to memory, the CGGA updates the data and tag caches as well as system memory. If writes are separated by 12 or more machine cycles, the CGGA acts as an interface to allow asynchronous operation of the the processor bus and the system bus. In this case, the 65C02 can continue mnning at 4 MHz while the CGGA writes the data to system RAM at 1.023 MHz. Each time firmware or software accesses port 1, 2, 5, or 6 by addressing SCOnx (where n is the port number + 8), the Apple lie Plus switches to 1.023 MHz operation for approximately 50 ms. When the speaker or game paddle is accessed, the Apple He Plus switches to 1.023 MHz operation for approximately 5 ms. The Apple He Plus does not switch back to 4 MHz operation until approximately 50 ms after the last access to SCOnx (or 5 ms after the last access to the speaker or game paddle). Figure 11-14 shows the pinout assignments for the Apple lie Plus CGGA chip. Table 11-16 describes the pin functions for the CGGA. • Figure 11-14 Apple He Plus accelerator chip pinouts h- o T- UJ I- O CO Q > > > Q 2 O i > T- CM T- T- O < CO Q in m m GO ,- co < Q < 0- r- O- r- O Z r > + + + < D rr nnnnnnnnnnnnnnnnnnnnn >-0010)S(0«l» O T- CM CO <• in co it: Q • CO -I > o o g g m o o £ << in t CO o 0.0,0.0. ^ 2 a. Q. 0. 330 Apple He Technical Reference Table 11-16 Apple He Plus accelerator chip signal descriptions Pin Signal In/Out Description 1 VSS Input Power and signal ground reference 2 I6M Input Master clock for CGGA 3 NC Output Not connected 4 a Input Ground 5 TDO I/O Tag RAM data bit 0 6 PA12 Input Processor address bit 12 7 TD1 I/O Tag RAM data bit 1 8 PAH Input Processor address bit 11 9 TD2 I/O Tag RAM data bit 2 10 PA10 Input Processor address bit 10 11 TD3 I/O Tag RAM data bit 3 12 OF Output Tag and data RAM output enable 13 TD4 I/O Tag RAM data bit 4 14 WE* Output Tag and data RAM write enable 15 PA9 Input Processor address bit 9 16 TD5 I/O Tag RAM data bit 5 17 PA8 Input Processor address bit 8 18 TD6 I/O Tag RAM data bit 6 19 TD7 I/O Tag RAM data bit 7 20 DD Input Ground 21 VSS Input Power and signal ground reference 22 VDD Input +5V 23 PDO I/O Processor bus data bit 0 24 PA7 Input Processor address bit 7 25 PD1 I/O Processor bus data bit 1 36 PA6 Input Processor address bit 6 27 PD2 I/O Processor bus data bit 2 28 PA5 Input Processor address bit 5 29 PD3 I/O Processor bus data bit 3 30 PA4 Input Processor address bit 4 31 PD4 I/O Processor bus data bit 4 32 PA3 Input Processor address bit 3 33 PD5 I/O Processor bus data bit 5 31 PA2 Input Processor address bit 2 35 PD6 I/O Processor bus data bit 6 36 PA1 Input Processor address bit 1 57 PD7 I/O Processor bus data bit 7 CHAPTER 11 Hardware 331 Table 11-16 Apple He Plus accelerator chip signal descriptions (continued) Hn Signal In/Out Description 38 PAO Input Processor address bit 0 39 PA13 Input Processor address bit 13 40 PAH Input Processor address bit 14 41 SI Input Tied to +5V 42 VDD Input +5V 43 VSS Input Power and signal ground reference 44 PCLK Output Processor clock output (0-4 MHz) 45 BS Input Ground 46 PR/W' Input Processor read/write signal 47 PA15 Input Processor address bit 15 48 NC Output Not connected 49 PHO Input System clock, phase 0 50 A15 Output System address bit 15 51 A14 Output System address bit 14 52 A13 Output System address bit 13 53 DO I/O System data bit 0 51 A12 Output System address bit 12 55 All Output System address bit 11 56 Dl I/O System data bit 1 57 A10 Output System address bit 10 LATCH 16 R / W 80 £=4 ^> ENB0- 80DIR 15 In> Auxiliary ~^> 80 LATCH RAM V \7 R / W80 | PRAS 03 \7 II if PHO PH1 ROM addressing The operating firmware for the Apple lie family computers is permanently stored in a lype 23256 (32 KB) ROM IC—called the Monitor ROM—as shown in Figure 11-16 and Table 11-17. The operating firmware is all of the firmware routines that "mn" the Apple lie family computers, like Applesoft, the Monitor, and the video firmware. A Original lie The original Apple He uses a smaller 23128 (16 KB) ROM IC for the Monitor ROM. A CHAPTER 11 Hardware 335 Figure 11-16 23256 ROM pinouts -5V , ^ 28 ~5V A12 2 27 (N.C.) A7 3 26 A13 A6 4 25 A8 A5 5 24 A9 A4 6 23 A11 A3 7 22 OE- A2 8 21 A10 A1 9 20 CE- AO 10 19 D7 DO 11 18 D6 D1 12. 17 D5 D2 13 16 D4 GND 14 15 D3 Table 11-17 23256 ROM signal descriptions Pin Signal Description 1 +5V +5 volts 2 A12 System address line 12 3 A7 System address line 7 4 A6 System address line 6 5 A5 System address line 5 6 A4 System address line 4 7 A3 System address line 3 8 A2 System address line 2 9 Al System address line 1 10 AO System address line 0 11 DO System data line 0 12 Dl System data line 1 13 D2 System data line 2 14 GND Ground 15 D3 System data line 3 16 D4 System data line 4 17 D5 System data line 5 18 D6 System data line 6 19 D7 System data line 7 20 CP Chip enable 21 A10 System address line 10 22 OP Output enable 336 Apple He Technical Reference Table 11-17 23256 ROM signal descriptions (continued) Pin Signal Description I] All System address line 11 24 A9 System address line 9 25 A8 System address line 8 2) A13 System address line 13 27 RA14 ROM address line 14 (from IOU; ihis pin is not connected on 23128 ROM) 28 +5V +5 volls The other ROMs in the Apple lie family computers are a type 2316 ROM (see Figure 11-17 and Table 11-18) used for the keyboard character decoder, and a type 2364 ROM (see Figure 11-18 and Table 11-19) used for character sets for the video display. The 2316 ROM is called the keyboard ROM and the 2364 ROM is called ihe character generator ROM. The 2364 ROM is rather large because it includes a section of straight-through bit mapping for the graphics modes. This way, graphics display video can pass through the same circuits as text without additional switching circuitry. • Figure 11-17 2316 ROM pinouts KA7 1 ^ 24 f5V KA6 2 23 KA8 KA5 3 22 CAPS KA4 4 21 -5V KA3 5 20 KBD- KA2 6 19 LANGSW KA1 7 18 GND KAO 8 17 (N.C.) DO 9 16 D6 D1 10 15 D5 D2 11 14 D4 GND 12 13 D3 Table 11-18 2316 ROM signal descriptions PJn Signal Description 1 KA7 Keyboard address line 7 2 KA6 Keyboard address line 6 3 KA5 Keyboard address line 5 4 KA4 Keyboard address line 4 CHAPTER 11 Hardware 337 Table 11-18 2316 ROM signal descriptions (continued) Pin Signal Description 5 KA3 Keyboard address line 3 6 KA2 Keyboard address line 2 7 KA1 Keyboard address line 1 8 KAO Keyboard address line 0 9 DO System data line 0 10 Dl System data line 1 li D2 System data line 2 12 GND Ground 13 D3 System data line 3 14 D4 System data line 4 15 D5 System data line 5 16 D6 System data line 6 17 N.C. Not connected 18 GND Ground 19 LANGSW Language switch 20 KBD* Enables keyboard data lines 21 +5V +5 volts 22 CAPS Caps Lock 23 KA8 Keyboard address line 24 +5V +5 volts Figure 11-18 2364 ROM pinouts + 5V 1 ^ 28 -r5V A12 2 27 + 5V A7 3 26 + 5V A6 4 25 A8 A5 5 24 A9 A4 6 23 A11 A3 7 22 GND A2 8 21 A10 A1 9 20 WNDW AO 10 19 07 OO 11 18 06 01 12 17 05 02 13 16 04 GND 14 15 03 338 Apple He Technical Reference Table 11-19 2364 ROM signal descriptions Pin Signal Description 1 +5V +5 volts 2 LANGSW Language switch 3 VIDD4 Video data line 4 4 VIDD3 Video data line 3 5 V1DD2 Video data line 2 6 VIDD1 Video data line 1 7 VIDDO Video data line 0 8 VC VC bit from IOU 9 SEGB SEGB bit from IOU 10 SEGA SEGA bit from IOU u OO Video output line 0 12 01 Video output line 1 13 02 Video output line 2 l-i GND Ground 15 03 Video output line 3 16 04 Video output line 4 17 05 Video output line 5 18 06 Video output line 6 19 07 Video output line 7 2D WNDW* Display blanking signal 21 RA10* Video display control bit 22 GND Ground 23 GR Graphics mode enable 24 RAS* Row address strobe 25 VIDD5 Video data line 5 26-28 +5V +5 volts RAM addressing The system RAM in the Apple lie family computers is used both for program and data storage and for the video display. The areas in RAM that are used for the display are accessed both by the 65G02 microprocessor and by the video display circuits. In some computers, this dual access results in addressing conflicts (cycle stealing) that can cause temporary dropouts in the video display. This problem does not occur in the Apple He family computers, due to the way the microprocessor and the video circuits share the memory. CHAPTER 11 Hardware 339 The memory circuits in the Apple He family computers take advantage of the two-phase system clock to interleave the microprocessor memory accesses and the display memory accesses so that they never interfere with each other. The microprocessor reads or writes to RAM only during PHO, and the display circuits read data only during PHI. Dynamic RAM refreshment The image on a video display is not permanent; it fades rapidly and must be refreshed periodically. To refresh the video display, each Apple He family computer reads the data in the active display page and sends them to the display. To prevent visible flicker in the display, and to conform to standard practice for broadcast video, the Apple lie family computer refreshes the display 60 times per second. The dynamic RAM devices used in the Apple lie family computers also need a kind of refreshment, because the data are stored in the form of electric charges that diminish with time and musi be replenished. The Apple lie family computers are designed so that refreshing the display also refreshes the dynamic RAMs. The next few paragraphs explain how this is done. The job of refreshing the dynamic RAM devices is minimized by the structure of the devices themselves. The individual data cells in each RAM device are arranged in a rectangular array of rows and columns. When the device is addressed, the part of the address that specifies a row is presented first, followed by the address of the column. Splitting information into parts that follow each other in time is called multiplexing. Because only half of the address is needed at one time, multiplexing the address reduces the number of pins needed for connecting the RAMs. The pinouts of the 64 KB RAM chip are shown in Figures 11-19 and Table 11-20. The pinouts of the 256 Kbit RAM chip are shown in Figure 11-20 and Table 11-21. A Apple He Plus The memory expansion Apple He and the Apple lie Plus replace the sixteen Memory expansion 64 KBit RAM ICs with four 256 Kbit RAM ICs. These RAM ICs are functionally identical to the ICs they replace, A 340 Apple lie Technical Reference Figure 11-19 64 Kbit RAM pinouts • 5V 1 ^ 16 GND MDx 2 15 CAS' R/W 3 14 MDx RAS- 4 13 RA1 RA7 5 12 RA4 RA5 6 11 RA3 RA6 7 10 RA2 • 5V 8 9 RAO Table 11-20 64 Kbit RAM signal descriptions Pin Signal Description 1 +5V +5 volts 2 Dx Data line 3 R/W* Read/write r 4 5 6 RAS* RA7 RA5 Row address strobe RAM address line 7 RAM address line 5 7 RA6 RAM address line 6 8 +5V +5 volts 9 RAO RAM address line 0 10 RA2 RAM address line 2 11 RA3 RAM address line 3 12 RA4 RAM address line 4 13 RA1 RAM address line 1 14 Dx Data line 15 CAS' Column address strobe 16 GND Ground CHAPTER 11 Hardware 341 Figure 11-20 Pinouts of 256 Kbit RAM chip GND 1 O" 18 GND Dx 2 17 Dx Dx 3 16 CAS* WE" 4 15 Dx RAS' 5 14 RA6 RAO 6 13 RA3 RA2 7 12 RA4 RA1 8 11 RA5 +5V 9 10 RA7 Table 11-21 256 Kbit RAM signal descriptions Pin Signal Description 1 GND Ground 2 Dx Data line 3 Dx Data line 4 WE* Write enable 5 RAS* Row address strobe 6 RAO RAM address line 0 7 RA2 RAM address line 2 8 RA1 RAM address line 1 9 +5V +5 Volts 10 RA7 RAM address line 7 11 RA5 RAM address line 5 12 RA4 RAM address line 4 13 RA3 RAM address line 3 14 RA6 RAM address line 6 15 Dx Data line 16 CAS* Column address strobe 17 Dx Data line 18 GND Ground Different manufacturers' 64 Kbit RAMs have cell arrays of either 128 rows by 512 columns or 256 rows by 256 columns. Only the row portion of the address is used in refreshing the RAMs. 342 Apple He Technical Reference Now consider how the display is refreshed. As described later in this chapter, the display circuitry generates a sequence of 8,192 memory addresses in Hi-Res mode; in text and Lo-Res modes, this sequence is the 1,024 display- page addresses repeated 8 times. The display address cycles through this sequence 60 times a second, or once every 17 milliseconds. The way the low-order address lines are assigned to the RAMs, the row address cycles through all 256 possible values once every 2 milliseconds (see Table 11-22). This more than satisfies the refresh requirements of the dynamic RAMs. • Table 11-22 RAM address multiplexing Mu.x'd address Row address Column address RAO AO A9 RA1 Al A6 RA2 A2 A10 RA3 A3 All RA4 A4 A12 RA5 A5 A13 RA6 A7 A14 RA7 A8 A15 Dynamic RAM timing The microprocessor clock of the Apple He runs at a speed of 1.023 MHz, but the interleaving of CPU and display cycles means that the RAM is being accessed at a 2 MHz rate, or a cycle time of just under 500 nanoseconds. Data for the CPU are strobed by the falling edge of PHO, and display data are strobed by the falling edge of PHI, as shown in Figure 11-21. The RAM timing looks complicated because the RAM address is multiplexed, as described previously. The MMU takes care of multiplexing the address for the CPU cycle, and the IOU performs the same function for the display cycle. The multiplexed address is sent to the RAM ICs over the lines RA0-RA7 (Table 11-23). Along with the other timing signals, the TMG generates two signals that control the RAM addressing: row-address strobe (RAS) and column-address strobe (CAS). CHAPTER 11 Hardware 343 Table 11-23 RAM timing signals Signal Description PHO System clock, phase 0 (CPU phase) PHI System clock, phase 1 (video phase) RAS Row-address strobe CAS Column-address strobe 03 Alternate RAM/column-address strobe RA0-RA7 Multiplexed address bus MD0-MD7 Internal data bus 344 Apple He Technical Reference Figure 11-21 RAM timing signals MM nmnjnLrLJiJwijWL^^ Q3 PHO PH1 RAS* CAS" RAO-RA7 oo-oo-o< MDO-MD7 <: > <—> The Apple He Plus MIG RAM The MIG circuit in the Apple He Plus computer uses a 16 KBit static RAM chip to provide a RAM buffer for the 3.5-inch disk drives. This RAM, which does not have to be refreshed, is dedicated to the disk drive interface and should not be used by programs. The pinouts of the MIG RAM chip are shown in Figure 11-22 and Table 11-24. CHAPTER 11 Hardware 345 • Warning Do not attempt to use the MIG RAM for program data; doing so may corrupt disk drive data, A Figure 11-22 MIG RAM pinouts RAMA7 1 KJ 24 +5V RAMA6 2 23 RAMA8 RAMA5 3 22 RAMA9 A4 4 21 W A3 5 20 GND A2 6 19 RAMA10 A1 7 18 RAMEN- AO 8 17 D7 DO 9 16 D6 D1 10 15 D5 D2 11 14 D4 GND 12 13 D3 Table 11-24 MIG RAM signal descriptions Hn Signal Description 1 RAMA7 RAM address line 7 2 RAMA6 RAM address kube 6 3 RAMA5 RAM address line 5 4 A4 System address line 4 5 A3 System address line 3 6 A2 System address line 2 7 Al System address line 1 8 AO System address lineO 9 DO Data line 0 to Dl Data line 1 11 D2 Data line 2 12 GND Ground 13 D3 Data line 3 14 D4 Data line 4 15 D5 Data line 5 16 D6 Data line 6 17 D7 Data line 7 18 RAMEN* RAM enable 346 Apple lie Technical Reference Table 11-24 MIG RAM signal descriptions (continued) Pin Signal Description 19 RAMA10 RAM address line 10 20 GND Ground 21 W* Write 22 RAMA9 RAM address line 9 23 RAMA8 RAM address line 8 24 +5V +5 volts The Apple lie Plus accelerator cache RAM The Apple lie Plus computer uses two 8 KB static RAM chips to provide a data cache for the accelerator circuit. This RAM is used for program instmctions, operands, and data. The cache RAM, which does not have to be refreshed, cannot be directly addressed by programs. The pinouts of the cache RAM chips are shown in Figure 11-23. For the uses of these signals, see Table 11-25 and 11-26. • Figure 11-23 Accelerator cache RAM pinouLs N.C. 1 W 28 +5V N.C. 1 V_^ 28 +5V PA12 2 27 WE* PA12 2 27 WE' PA7 3 26 +5V PA7 3 26 +5V PA6 4 25 A8 PA6 4 25 A8 PAS 5 24 A9 PA5 5 24 A9 PA4 6 DATA 23 A11 PA4 6 TAG 23 A11 PA3 7 22 OE' PA3 7 22 OE' PA2 8 21 A10 PA2 8 21 A10 PA1 9 20 GND PA1 9 20 GND PAO 10 19 PD7 PAO 10 19 TD7 PDO 11 18 PD6 TDO 11 18 TD6 PD1 12 17 PD5 TD1 12 17 TD5 PD2 13 16 PD4 TD2 13 16 TD4 GND 14 15 PD3 GND 14 15 TD3 CHAPTER 11 Hardware 347 Table 11-25 Cache data RAM signal descriptions Pin Signal Description 1 N.C. Not connected 2 PA12 Processor address line 12 3 PA7 Processor address line 7 4 PA6 Processor address line 6 5 PA5 Processor address line 5 6 PA4 Processor address line 4 7 PA3 Processor address line 3 8 PA2 Processor address line 2 9 PA1 Processor address line 1 10 PAO Processor address line 0 11 PDO Processor data lineO 12 PD1 Processor data line 1 13 PD2 Processor data line 2 14 GND Ground 15 PD3 Processor data line 3 16 PD4 Processor data line 4 17 PD5 Processor data line 5 18 PD6 Processor data line 6 19 PD7 Processor data line 7 20 GND Ground 21 A10 System address line 10 22 OP Output enable 23 All System address line 11 24 A9 System address line 9 25 A8 System address line 8 26 +5V +5 volts 27 WE* Write enable 28 +5V +5 volts 348 Apple lie Technical Reference Table 11-26 Cache tag RAM signal descriptions Hn Signal Description 1 N.C. Not connected 2 PA12 Processor address line 12 3 PA7 Processor address line 7 4 PA6 Processor address line 6 5 PA5 Processor address line 5 6 PA4 Processor address line 4 7 PA3 Processor address line 3 8 PA2 Processor address line 2 9 PA1 Processor address line 1 10 PAO Processor address line 0 11 TDO Tag data line 0 12 TD1 Tag data line 1 13 TD2 Tag data line 2 14 GND Ground 15 TD3 Tag data line 3 16 TD4 Tag data line 4 17 TD5 Tag data line 5 18 TD6 Tag data line 6 19 TD7 Tag data line 7 '20 GND Ground 21 A10 System address line 10 22 OE* Output enable 23 All System address line 11 24 A9 System address line 9 25 A8 System address line 8 25 +5V +5 volts 27 WE* Write enable 28 +5V +5 volts CHAPTER 11 Hardware 349 The keyboard The keyboard is a matrix of key switches connected to an AY-3600-type keyboard decoder via a ribbon cable and a 34-pin connector. Figure 11-24 is a block diagram of the keyboard circuit. The AY-3600 scans die array of keys over and over to detect any keys pressed. The scanning rate and debounce lime are set by an external resistor- capacitor network. The Apple He Plus keyboard has a slightly different key arrangement than that of the Apple lie. The Apple lie Plus has no 40/80 column switch, and the volume control is located on the keyboard rather than on the side of the machine. The Option key on the Apple He Plus keyboard is the same as the Solid Apple key on older Apple lie keyboards. Functionally, the Apple He and Apple lie Plus keyboards are identical. 350 Apple lie Technical Reference Figure 11-24 Keyboard circuit block diagram ( Address Bus J> iMMUl C06X- All A1 A2 Data Bus t> CAPL OAPL 11 8 to 1 MUX 7S 80COLSW 10 DO-6 \BD- To: 65C02 IMMUI- LANGSW IOU 2716 MAP IWM CAPS GLU SER1 SER2 CONTROL SHIFT Hi eyooard Address Bus AO-8 AY-3600-PROKEY KSTRB AKD (SEH2) (IOU) n (IOU) /reset h B~ 1BX.Y C o o r d i n a l e s / / FLASH (12 Volt Circuits) (Internal Disk Connector) y tfttli 0 zr CHAPTER 11 Hardware 351 The AY-3600 outputs include five bits of key code plus separate lines for Control, Shift, any-key-down (AKD), and keyboard strobe (KSTRB). The AKD and KSTRB lines are connected to the IOU. The key-code line and Control and Shift arc inputs to a separate 2316 ROM. (Some Apple lie computers have a 2716 EPROM chip, which is functionally equivalent to the 2316 ROM chip.) The ROM translates the key codes to character codes, which arc enabled onto the data bus by the KBD* signal. The KBD* signal is enabled by the MMU whenever a program reads location $COO0. Figure 11-25 shows the keyboard connector. Table 11-27 shows the signal assignments for the keyboard connector in the original, UniDisk 3.5, and memory expansion versions of the Apple lie computer. Table 11-28 shows the signal assignments for the keyboard connector in the Apple lie Plus computer. • Figure 11-25 Keyboard connector Keyboard 0 © © © © © © © © © © © © © © © © © © © © © © © © © © © © © © © © © 352 Apple lie Technical Reference Table 11-27 Apple He keyboard connector signals Pin Signal Description 1 Y7 Y coordinate bit 7 2 Y9 Y coordinate bit 9 3 X4 X coordinate bit 4 4 Y8 Y coordinate bit 8 5 X5 X coordinate bit 5 6 Y5 Y coordinate bit 5 7 X6 X coordinate bit 6 8 Y3 Y coordinate bit 3 9 X7 X coordinate bit 7 10 Y6 Y coordinate bit 6 11 DISKACTY Disk activity light 12 XO X coordinate bit 0 14 Y4 Y coordinate bit 4 15 LANGSW Keyboard (Dvorak) switch 16 CAPL Option (Solid Apple) keyf 18 X2 X coordinate bit 2 19 80COLSW 40/80 column switch 20 X3 X coordinate bit 3 21 GND Ground 22 Y2 Y coordinate bit 2 23 +5V +5 volts 24 Yl Y coordinate bit 1 25 +5V +5 volts 26 OAPL Command (Open Apple) key 27 GND Ground 2S CAPS Caps Lock key 29 RESET* Reset key 31 YO Y coordinate bit 0 32 CONTROL Control key 33 XI X coordinate bit 1 34 SHIFT Shift key f CAPL is an acronym for "Closed Apple," an alternate name for the Solid Apple key. CHAPTER 11 Hardware 353 Table 11-28 Apple He Plus keyboard connector signals Pin Signal Description 1 Y7 Y coordinate bit 7 2 Y9 Y coordinate bit 9 3 X4 X coordinate bit 4 4 Y8 Y coordinate bit 8 5 X5 X coordinate bit 5 6 Y5 Y coordinate bit 5 7 X6 X coordinate bit 6 8 Y3 Y coordinate bit 3 9 X7 X coordinate bit 7 10 Y6 Y coordinate bit 6 11 DISKACTY Disk activity light 12 XO X coordinate bit 0 14 Y4 Y coordinate bit 4 15 VOLUME Volume control 16 CAPL Option keyf 18 X2 X coordinate bit 2 19 LANGSW Keyboard (Dvorak) switch 20 X3 X coordinate bit 3 21 GND Ground 22 Y2 Y coordinate bit 2 23 +5V +5 VDC 24 Yl Y coordinate bit 1 25 +5V +5 VDC 26 OAPL Command (Open Apple) key 27 GND Ground 28 CAPS Caps lock key 29 RESET* Reset key 31 YO Y coordinate bit 0 32 CONTROL Control key 33 XI X coordinate bit 1 31 SHIFT Shift key t CAPL is an acronym for "Closed Apple," a reference to the label on this key on older Apple lie computers. 354 Apple He Technical Reference Figure 11-26 illustrates the events that occur when a key is pressed, when the keypress is detected by a program, and when a key is pressed and held for more than about a second. • Figure 11-26 Keyboard signals Decode of $C01x in IOU If IOU sees AKD too long. Key Key clears keyboard strobe Another key it generates own strobe pressed released (bit 7 at $C00x) pressed for auto-repeat 'r \ <\ \• • Keyboard strobe to IOU n . ni 1 • i• Latched KSTRB from IOU on $C0Ox bit 7 > 0.8 to 1.07 •r -* seconds >- AKDa1$C01x bit / r CHAPTER 11 Hardware 355 The speaker The built-in speaker is controlled by a single bit of output from the input/output unit (IOU). In the original, UniDisk 3.5, and memory expansion versions of the Apple lie, this bit is input to the sound hybrid circuit (AUD) shown in Figure 11-27, which amplifies the pulse. In the Apple lie Plus, the sound circuit is implemented as discrete components on the main logic board. The function of the sound circuit in the Apple lie Plus is identical to that of the hybrid sound circuit in the Apple He, except that the external headphone jack is not supported in the Apple He Plus. 356 Apple He Technical Reference Figure 11-27 Speaker circuit diagram r 5V I 500 Si "• Volume ^Control IVSOUND^ To Video Expansion Connector SPKR IOU AUD JYYYYl. EAROUT2 ^e Binaural Jack JYYYYV J\ i<- EAROUT1 EAROUT VGND O VGND ^4 Speaker CHAPTER 11 Hardware 357 Volume control There is a 500-ohm (1-kilohm in the Apple lie Plus) variable resistor feeding anywhere from 0 to 5 volts to the speaker circuit to control the speaker volume. The Apple He has a volume control knob on the side of the machine. The Apple lie Plus has a sliding volume control on the keyboard. Audio output jack Next to the volume control, along the lower-left side of the Apple He case, there is a 35 mm audio output jack. Although speaker output is monaural, the jack accommodates stereo headphone plugs (as well as monaural), providing sound to both channels. Inserting a headphone plug into the jack disconnects the built-in speaker. A Apple lie Plus The Apple He Plus has no audio output jack, A The video display The Apple He family computers produce a video signal that creates a display on a standard video monitor or, if you add an RF modulator, on a black-and-white or color television set. The video signal is a composite made up of the data that are being displayed plus the horizontal and vertical synchronization signals that the video monitor uses to arrange the lines of display data on the screen. 358 Apple He Technical Reference • Note: Apple lie family computers manufactured for sale in the USA generate a video signal that is compatible with the standards set by the NTSC (National Television Standards Committee). Apple He family computers used in European countries require an external adapter to provide video that is compatible with the standard used there, which is called PAL (for phase alternating lines). References to the PAL standard are found in the bibliography at the end of this manual. This manual describes only the NTSC version of the video circuits. The display portion of the video signal is a time-varying voltage generated from a stream of data bits, where a 1 corresponds to a voltage that generates a bright dot, and a 0 to a dark dot. The display bit stream is generated in bursts that correspond to the horizontal lines of dots on the video screen. The signal named WNDW' is low during these bursts. During the time intervals between bursts of data, nothing is displayed on the screen. During these intervals, called the blanking intervals, the display is blank and the WNDW' signal is high. The synchronization signals, called sync for short, are produced by making the signal named SYNC low during portions of the blanking intervals. The sync pulses are at a voltage equivalent to blacker-than-black video and don't show on the screen. The video counters The address and timing signals that control the generation of the video display are all derived from a chain of counters inside the IOU. Only a few of these counter signals are accessible from outside the IOU, but they are all important in understanding the operation of the display generation process, particularly the display memory addressing described in the next section. The horizontal counter is made up of seven stages: HO, HI, H2, H3, H4,115, and HPE'. The input to the horizontal counter is the 1 MHz signal that controls the reading of data being displayed. The complete cycle of the horizontal counter consists of 65 states. The six bits HO through H5 count from 0 to 64, then start over at 0. Whenever this happens, HPE* forces another count with HO through H5 held at 0, extending the total count to 65. The IOU uses the 40 horizontal count values from 25 through 64 in generating the low-order part of the display data address. The IOU uses the count values from 0 to 24 to generate the horizontal blanking, the horizontal sync pulse, and the color-burst gate. CHAPTER 11 Hardware 359 When the horizontal count gets to 65, it signals the end of a line by triggering the vertical counter. The vertical counter has nine stages: VA, VB, VC, VO, VI, V2, V3, V4, and V5. When the vertical count reaches 262, the IOU resets it and starts counting again from 0. Only the first 192 scanning lines are actually displayed; the IOU uses the vertical counts from 192 to 262 to generate the vertical blanking and sync pulse. Nothing is displayed during the vertical blanking interval. (The vertical line count is 262 rather than the standard 262.5 because, unlike normal television, the Apple He family's video display is not interlaced.) Display memory addressing As described in Chapter 6, data bytes are not stored in memory in Lhe same sequence in which they appear on the display. You can get an idea of the way the display data are stored by using the Monitor to set the display to graphics mode, then storing data starting at the beginning of the display page at $0400 and watching the effect on the display. If you do this, you should use the graphics display instead of text to avoid confusion: the text display is also used for Monitor input and output. If you want your program to display data by storing them directly into the display memory, you must first transform the display coordinates into the appropriate memory addresses, as shown in Chapter 2. The descriptions that follow will help you understand how this address transformation is done and why it is necessary. The address transformation that folds three rows of 40 display bytes into 128 contiguous memory locations is the same for all display modes, so it is described first. The differences among the different display modes are described later in this chapter. Display address mapping Consider the simplest display on an Apple He family computer, the 40-column text mode. To address 40 columns requires 6 bits, and to address 24 rows requires another 5 bits, for a total of 11 address bits. Addressing the display this way would involve 2048 (2 to the 11th power) bytes of memory to display a mere 960 characters. The 80-column text mode would require 4096 bytes to display 1920 characters. The leftover chunks of memory that were not displayed could be used for storing other data, but not easily, because they would not be contiguous. 360 Apple He Technical Reference Instead of using the horizontal and vertical counts to address memory directly, the circuitry inside the IOU transforms them into the new address signals described below. The transformed display address must meet the following criteria: • map the 960 bytes of 40-column text into only 1024 bytes • scan the low-order address to refresh the dynamic RAMs • continue to refresh the RAMs during video blanking See the section "Dynamic RAM Refreshment" earlier in this chapter, for a discussion of RAM refreshing. The transformation involves only horizontal counts 113, H4, and H5, and vertical counts V3 and V4. Vertical count bits VA, VB, and VC address the lines making up the characters, and are not involved in the address transformation. The remaining low-order count bits, HO, HI, H2, VO, VI, and V2 are used directly and are not involved in the transformation. The IOU performs an addition that reduces the five significant count bits to four new signals SO, SI, S2, and S3, where S stands for sum. Figure 11-28 is a diagram showing the addition in binary form, with V3 appearing as the carry in and H5 appearing as its complement H5'. A constant value of 1 appears as the low-order bit of the addend. The carry bit generated with the sum is not used. If this transformation seems terribly obscure, try it with actual values. For example, for the upper-left corner of the display, the vertical count is 0 and the horizontal count is 24: HO, HI, H2, and H5 are 0's, and H3 and H4 are l's. The value of the sum is 0, so the memory location for the first character on the display is the first location in the display page, as you might expect. • Figure 11-28 Display address transformation V3 C a r r y in -.H5 V3 H4 H3 Augend V4 -H5 V4 1 Addend S3 S2 S1 SO Sum CHAPTER 11 Hardware 36l Horizontal bits HO, HI, and 112 and sum bits SO, SI, and S2 make up the transformed horizontal address (AO through A6 in Table 11-29). As the horizontal count increases from 24 to 63, the value of the sum (S3 S2 SI SO) increases from 0 to 4 and the transformed address goes from 0 to 39, relative to the beginning of the display page. • Table 11-29 Display memory addressing Memory Display address bit AO HO Al HI A2 H2 A3 SO A4 SI A5 S2 A6 S3 A7 VO A8 VI A9 V2 A10 All A12 A13 A14 A15 GN 'For these address bits, see Table 11-30. The low-order three bits of the vertical row counter are VO, VI, and V2. These bits control address bits A7, A8, and A9, as shown in Table 11-29, so that rows 0 through 7 start on 128-byte boundaries. When the vertical row counter reaches 8, VO, VI, and V2 are 0 again, and V3 changes to 1. If you do the addition in Figure 11-28 with H equal to 24 (the horizontal count for the first column displayed) and V equal to 8, the sum is 5 and the horizontal address is 40: the first character in row 8 is stored in the memory location 40 bytes from the beginning of the display page. 362 Apple He Technical Reference Table 11-29 shows how the signals from the video counters are assigned to the address lines. HO, HI, and H2 are horizontal-count bits, and VO, VI, and V2 are vertical-count bits. SO, SI, S2, and S3 are the folded address bits described earler. Table 11-30 shows memory address bits for the display modes. • Table 11-30 Memory address bits for display modes Address bit Text and Lo-Res Hi-Res and Double Iti-Rcs A10 80Storc AND NOT Page2 VA All /80Store AND Page2f VB A12 0 VC A13 0 80Store AND NOT Page2 A14 0 80Store AND Page2 Note: AND and NOT refer to the logical (Boolean) AND and inverse operations. Figure 11-29 shows how groups of three 40-character rows are stored in blocks of 120 contiguous bytes starting on 128-byte address boundaries. This diagram is another way of describing the display mapping shown in Chapter 6. Notice that the three rows in each block of 120 bytes are not adjacent on the display. CHAPTER 11 Hardware 363 • Figure 11-29 40-column text display memory Memory locations marked with a double asterisk (") are screen holes, described in Chapter 2. „ 8 Bytes $400 Row 0 Row 8 Row 16 $480 Row 1 Row 9 Row 17 S500 Row 2 Row 10 Row 18 S580 Row 3 Row 1 1 Row 19 $600 Row 4 Row IP Row 20 $680 Row 5 Row 13 Row 21 S700 Row 6 ROW 14 Row ?2 $780 Row 7 Row 15 Row 23 364 Apple He Technical Reference Video display modes The different display modes all use the address-mapping scheme described in the preceding section, but they use different-sized memory areas in different locations. This section describes the addressing schemes and the methods of generating the actual video signals for the different display modes. Figure 11-30 illustrates the video display circuits discussed in this section. CHAPTER 11 Hardware 365 Figure 11-30 Video display circuits VIDD7 IVSOUND 1 12V AUD GND 366 Apple lie Technical Reference Text displays The Text and Lo-Res graphics pages begin at memory locations $0400 and $0800. Table 11-30 shows how the display-mode signals control the address bits to produce these addresses. Address bits A10 and All are controlled by the settings of Page2 and 80Store, the display-page and 80-column-video soft switches. Address bits A12, A13, and A14 are set to 0. Note that 80Store active inhibits Page2: there is only one display page in 80- column mode. The low-order 6 bits of each data byte reach the character generator directly, via the video data bus VID0-VTD5. The two high-order bits are modified by the IOU to select between the primary and alternate character sets and are sent to the character generator on lines RA9 and RA10. The data for each row of characters are read eight times, once for each of the eight lines of dots making up the row of characters. The data bits are sent to the character generator along with VA, VB, and VC, the low-order bits from the vertical counter. For each character being displayed, the character generator puts out one of eight stored bit patterns selected by the 3-bit number made up of VA, VB, and VC. The bit patterns from the character generator are loaded into the 74166 parallel-to-serial shift register and output as a serial bit stream that goes to the video output circuit (see Figure 11-30). The shift register is controlled by signals LDPS' (load parallel-to-serial shifter) and VID7M (video 7 MHz). In 40-column mode, LDPS* strobes the output of the character generator into the shift register once each microsecond and VID7M shifts the bits out at 7 MHz (see Figure 11-31). The addressing for the 80-column display is exactly the same as for the 40-column display: the 40 columns of display memory in auxiliary memory are addressed in parallel with the 40 columns in main memory. The data from these two memories reach the video data bus (lines VID0-VID7) via separate 74LS374 tri-state buffers. These buffers are loaded simultaneously (at the rising edge of PHO), but their outputs are sent to the character generator alternately by the falling edge of PHO and PHI. In 80-column mode, LDPS* loads data from the character generator into the shift register twice during each microsecond, once during PHO and once during PHI, and VID7M remains low, enabling the clock continuously at 14M (see Figure 11-32). CHAPTER 11 Hardware 367 Figure 11-31 7 MHz video timing signals: 40-column, Lo-Res, and Hi-Res display 14M iirmrLjmrmnji^ 7M 00 —i CPU Phase Video Phase 01 — I Data Bus "X X I VIDEO LATCH X IX LDPS' and EN80" i_r Video Bus into CHAR GEN K ~x Output Bus into SPI (Shift Register) X. ~x i i i i i i y j SPI Serial Output (VID7M and 14M) 368 Apple lie Technical Reference Figure 11-32 14 MHz video timing signals: 80-column and Double Hi-Res display 14M nj^jwinmrin^^ oO 01 —I Data Bus VIDEO LATCH ALT Alternate Bus X o X 80 LATCH I X LDPS* (EN80* always on) Video Bus into Char Gen ALT y Q x^; Output Bus into SPI (Shift Register) x: ~x ALT0 -yo: SPI Serial Output (14M Clock) II " t t t t t t t t t t t " jmjrnjinnjnLjTjmjmnjmj Lo-Res display In the graphics modes, VA and VB are not used by the character generator, so the IOU uses lines SEGA and SEGB to transmit HO and IIIRES*, as shown in Table 11-31. CHAPTER 11 Hardware 369 Table 11-31 Character-generator control signals IOU Pin lou signal name Text mode Graphics mode 3 SEGA VA HO 4 SEGB VB HIRES' 5 SEGC VC VC '1 Tie Lo-Res graphics display uses VC to divide the eight display lines corresponding to a row of characters into two groups of four lines each. Each row of data bytes is addressed eight times, the same as in Text mode, but each byte is interpreted as two nibbles. Each nibble selects 1 of 16 colors. During the upper four of the eight display lines, VC is low and the low-order nibble determines the color. During the lower four display lines, VC is high and the high-order nibble determines the color. The bit patterns that produce the Lo-Res colors are read from the character-generator ROM in the same way the bit patterns for characters are produced in Text mode. The 74166 parallel-to-scrial shift register converts the bit patterns to a serial bit stream for the video circuits (Figure 11-30). The video signal generated by the Apple lie family includes a short burst of 3.58 MHz signal that is used by an NTSC color monitor or color TV set to generate a reference 3.58 MHz color signal. The video signal of the Apple Ilc-family computers produce color by interacting with this 3.58 MHz signal inside the monitor or TV set. Different bit patterns produce different colors by changing the duty cycles and delays of the bit stream relative to the 3.58 MHz color signal. To produce the small delays required for so many different colors, the shift register runs at 14 MHz and shifts out 14 bits during each cycle of the 1 MHz data clock. To generate a stream of 14 bits from each 8-bit pattern read from the ROM, the output of the shift register is connected back to the register's serial input to repeat the same 8 bits; the last 2 bits are ignored the second time around. Each bit pattern is output for the same amount of time as a character: 1.02 microseconds. Because that is exactly enough time for three and a half cycles of the 3.58 MHz color signal, the phase relationship between the bit patterns and the signal changes by a half cycle for each successive pattern. To compensate for this, the character generator puts out one of two different bit patterns for each nibble, depending on the state of HO, the low- order bit of the horizontal counter. 370 Apple lie Technical Reference Hl-Res display The Hi-Res graphics pages begin at memory locations S2000 and $4000 (decimal 8192 and 16384). These page addresses are selected by address bits A13 and A14. In Hi-Res mode, these address bits are controlled by the Page2 and 80Store soft switches. As in Text mode, 80Store inhibits addressing of the second page because there is only one page of 80-column text available for mixed mode. In Hi-Res graphics mode, the display data are still stored in blocks like the one shown in Figure 11-29, but there are eight of these blocks. As Tables 11-30 and 11-31 show, vertical counts VA, VB, and VC are used for address bits A10, All, and A12, which address eight blocks of 1024 bytes each. Remember that in the display, VA, VB, and VC count adjacent horizontal lines in groups of eight. This addressing scheme maps each of those lines into a different 1024-byte block. It might help to think of this scheme as a kind of eight-way multiplexer: it's as if eight text displays were combined to produce a single Hi-Res display, with each Text display providing one line of dots in turn, instead of a row of characters. The Hi-Res bit patterns are produced by the character-generator ROM. In this mode, the bit patterns simply reproduce the 7 bits of display data. The low-order 6 bits of data reach the ROM via the video data bus VID0-VID5. The IOU sends the other 2 data bits to the ROM via RA9 and RA10. The Hi-Res colors described in Chapter 6 are produced by the interaction between the video signal the bit patterns generate and the 3.58 MHz color signal generated inside the monitor or TV set. The Hi-Res bit patterns are always shifted out at 7 MHz, so each dot corresponds to a half-cycle of the 3.58 MHz color signal. Any part of the video signal that produces a single white dot between two black dots, or vice versa, is effectively a short burst of 3.58 MHz and is therefore displayed as color. In other words, a bit pattern consisting of alternating l's and 0's gets displayed as a line of color. The Hi-Res graphics subroutines produce the appropriate bit patterns by masking the data bits with alternating l's and 0's. To produce different colors, the bit patterns must have different phase relationships to the 358 MHz color signal. If alternating l's and 0's produce a certain color, say green, then reversing the pattern to 0's and l's will produce the complementary color, purple. As in the Lo-Res mode, each bit pattern corresponds to three and a half cycles of the color signal, so the phase relationship between the data bits and the color signal changes by a half cycle for each successive byte of data. Here, however, the bit patterns produced by the hardware are the same for adjacent bytes; the color compensation is performed by the Hi-Res software, which uses different color masks for data being displayed in even and odd columns. CHAPTER 11 Hardware 371 To produce other colors, bit patterns must have other timing relationships to the 3-58 MHz color signal. In Hi-Res mode, the Apple He family produces two more colors by delaying the output of the shift register by half a dot (70 ns), depending on the high-order bit of the data byte being displayed. (The high-order bit doesn't actually get displayed as a dot, because at 7 MHz there is only time to shift out seven of the eight bits.) As each byte of data is sent from the character generator to the shift register, high-order data bit D7 is also sent to the TMG. If D7 is off, the TMG transmits shift-register timing signals LDPS* and VID7M normally. If D7 is on, the TMG delays LDPS' and V1D7M by 70 nanoseconds, the time corresponding to half a dot. The bit pattern that formerly produced green now produces orange; the pattern for purple now produces blue. • Timing: For 80-column text, the shift register is clocked at twice normal speed. When 80-column text is used with graphics in mixed mode, the TMG controls shift-register timing signals LDPS' and VID7M so that the graphics portion of the display works correctly even when the text window is in 80-column mode. Double Hi-Res display Double Hi-Res graphics mode displays 2 bytes in the time normally required for 1, but it uses Hi-Res graphics Pages 1 and IX instead of Text and Lo-Res Pages 1 and IX • Note: There is a second pair of bytes, HRP2 and HRP2X, which can be used to display a second Double Hi-Res page. Double Hi-Res graphics mode displays each pair of data bytes as 14 adjacent dots, 7 from each byte. The high- order bit (color-select bit) of each byte is ignored. The auxiliary-memory byte is displayed first, so data from auxiliary memory appear in columns 0-6,14-20, and so on, up to columns 547-552. Data from main memory appear in columns 7-13,21-27, and so on, up to 553-559. As in 80-column Text mode, there are twice as many dots across the display screen, so the dots are only half as wide. On a TV set or low-bandwidth (less than 14 MHz) monitor, single dots are dimmer than normal. • Note: Except for some expensive color monitors, any video monitor with a bandwidth as high as 14 MHz is a monochrome monitor. 372 Apple He Technical Reference The main memory and auxiliary memory are connected to the address bus in parallel, so both are activated during Lhe display cycle. The rising edge of PHO clocks a byte of main memory data into the video latch, and a byte of auxiliary memory data into the 80 latch (Figure 11-30). PHI enables output from the (auxiliary) 80 latch, and PHO enables output from the (main) video latch. Output from both latches goes to the character generator, where GR and SEGB* select Hi-Res graphics. LDPS' operates at 2 MHz in this mode, alternately gating lhe auxiliary byte and main byte into the parallel-to-serial shift register VID7M is active (kept true) for Double Hi-Res display mode, so when it is ANDcd with 14M, the result is still 14M. The 14M serial clock signal gates shift register output to VID, the video display hybrid circuit, for output to the display device. Video output signals The stream of video data generated by the display circuits described above goes to a hybrid circuit (VID) that adjusts the signals to the proper amplitudes and conditions the color burst. The resulting video signal is an NTSC-compatible composite-video signal that can be displayed on a standard video monitor. The signal is similar to the EIA (Electronic Industries Association) standard positive composile video. This signal is available in two places in Apple lie family computers (see Figure 11-33): • at the video output connector on the back of lhe Apple Ilc-family computer • at the video expansion connector (pin 12) on lhe back panel (see Table 11-32) Monitor output The sleeve of the video output connector at the center or the Apple lie back panel is connected to ground and the tip is connected to the video output through a resistor network that attenuates it to about 1 volt and matches its impedance to 75 ohms. This arrangement is suitable for most video monitors. CHAPTER 11 Hardware 373 1 • Figure 11-33 Video output back panel connectors luDI IOI r GND SI VIDOUT Back Panel Video Video Output Connector Expansion Connector (For a Monitor) (For an RF Modulator or Special Adaptor) (See Fig. 11-25) Video expansion output The back panel of an Apple He family computer has a DB-15 connector for sophisticated video interfaces external to the computer. 374 Apple lie Technical Reference Figure 11-34 shows the pin assignments for this connector; Table 11-32 describes the signals. In Table 11-32 the column labeled Derived from indicates what clock signals the video signals are derived from. LDPS', CREF, and PRAS have a maximum delay of 30 ns from the appropriate 14 MHz rising edge. SEROUT' is clocked out of a 74LS166 by the rising edge of 14M and has a maximum delay of 35 ns. VIDD7 is driven from a 74LS374 and has a maximum delay of 28 ns from the rising and (if 80-column) falling edges of PHI. To align CREF so it is in the same phase at the beginning of every line, certain clock signals must be stretched. This stretch is for one 7M cycle (140 ns), and occurs at the end of each video line. All timing signals except 14M, 7M, and CREF are stretched. • Warning The maximum allowable current drain of + 12V regulated power at the video expansion connector is 300 milliamps. If the external device draws more than this, it can damage the computer or cause the power supply to shut down. A • Warning The signals at the DB-15 on an Apple He are not the same as those at the DB-15 on the Apple IIGS. Do not attempt to plug a cable intended for one into the other, A A Important Several of the signals al the DB-15, such as 14 MHz, must be buffered within about 4 inches (10 cm) of lhe back panel connector—preferably inside a container directly connected to the back panel. For technical information, contact Apple Technical Support, A CHAPTER 11 Hardware 375 Figure 11-34 Video expansion connector pinouts 7 6 5 4 3 2 15 14 13 12 11 10 9 • • • • • • • Pin Signal Pin Signal 1 TEXT 9 PRAS* 2 14.M 10 GR 3 SYNC 11 SEROUT* 4 SEGB 12 NTSC 5 1VS0UND 13 GND 6 LDPS' 14 VI DDT 7 WNDW 15 CREF 8 + 12V • Table 11-32 Video expansion connector signals fin Derived from Signal Description 1 PHO TEXT Video text signal from TMG; set to inverse of GR, except in Double Hi-Res mode 2 14M 14 MHz master timing signal from the system oscillator 3 03 SYNC* Displays horizontal and vertical synchronization signal from IOU pin 39 376 Apple He Technical Reference Table 11-32 Video expansion connector signals (continued) Pin Derived from Signal Description PRAS SEGB Displays vertical counter bit from IOU pin 4; in Text mode indicates second low-order vertical counter; in graphics mode indicates Lo-Res 5 1VSOUND One-volt sound signal from pin 5 of the audio circuit (AUD) 6 14M LDPS* Video shift-register load enable from pin 12 of TMG 7 PRAS WND" Active area display blanking; includes both horizontal and vertical blanking 8 +12V Regulated +12 volts DC; can drive 300 mA 9 14M PRAS' RAM row-address strobe from TMG pin 19 10 PRAS GR Graphics mode enable from IOU pin 2 11 14M SEROUT* Serialized character-generator output from pin 1 of the 74LS166 shift register 12 NTSC Composite NTSC video signal from VID hybrid chip 13 GND Ground reference and supply 14 PHO VIDD7 From 74LS374 video latch; causes half-dot shift if high 15 14M CREF Color reference signal from TMG pin 3; 3.58 MHz Disk I/O Disk I/O for 5.25-inch drives is supported by lhe IWM disk controller unit. The 3.5-inch drives are supported through the IWM and the MIG. External drives are attached via a DB-19 connector. Figure 11-35 shows this connector. Table 11-33 describes the pin assignments for the disk connector on the original, UniDisk 3.5, and memory expansion versions of the Apple lie. Table 11-34 describes the pin assignments for the disk connector on the Apple lie Plus. Supply voltages come from the power supply; all other signals come from the IWM or MIG, as described in the sections "The Disk Controller Unit (IWM)" and "The Apple He Plus Multidrive Interface Glue (MIG)" earlier in this chapter. CHAPTER 11 Hardware 377 A Warning The power supply available at this connector is for a Disk He, UniDisk 3.5, Apple 3.5, or similar type drive only. Do not use power from the external disk connector for any other purpose—you may damage the internal power supply, A Figure 11-35 External disk drive connector n7 9 8 7 6 5 4 3 2 1 > \ • • • • • • • • • • / \ 19 18 17 16 1!> 14 13 12 11 / Pin Signal Pin Signal 1,2,3,4 GND 13 SEEKPH2 5 -12V 14 SEEKPH3 6 +5V 15 WRREQ* 7,8 + 12V 16 N.C. 9 EXTINT* 17 DR2* 10 WRPROT 18 RDDATA 11 SEEKPHO 19 WRDATA 12 SEEKPH1 378 Apple lie Technical Reference Table 11-33 External disk drive connector signals for the Apple He family Connector pin Signal Description 1,2,3,4 GND Ground 5 -12V -12 volts 6 +5V +5 volts 7J8 +12V +12 volts 9 EXTINT* External intermpt line 10 WRPROT Write-protect input 11 SEEKPHO Register select line CAO 12 SEEKPH1 Register select line CA1 13 SEEKPH2 Register select line CA2 14 SEEKPH3 Register write strobe LSTRB 15 WRREQ' Write data request 17 EN2' Drive 2 select 18 RDDATA Read data input 19 WRDATA Write data output Table 11-34 External disk drive connector signals for the Apple He Plus Connector pin Signal Description 1,2,3 GND Ground 4 3.5* 3.5-inch disk drive select 5 -12V -12 volts 6 +5V +5 volts 7,8 +12 +12 volts 9 ENBL' Drive 2 enable 10 SENSE Write-protect input n EXTSPHO Register select line CAO 12 SEEKPH1 Register select line CA1 13 SEEKPH2 Register select line CA2 14 SEEKPH3 Register write strobe LSTRB 15 WRREQ' Write data request 16 HDSEL2 Register select line SEL 17 EN1* Drive 1 enable 18 RDDATA Read daia input 19 WRDATA Write data output CHAPTER 11 Hardware 379 Figure 11-36 shows the internal disk drive connector for all versions of the Apple He, including the Apple He Plus. Table 11-35 describes the pin assignments for the Apple He computers, and Table 11-36 describes the pin assignments for the Apple lie Plus. • Figure 11-36 Internal disk drive connector for the Apple He and Apple lie Plus Internal disk © © ® ® © © © © © © © © © © © © © © © © 380 Apple lie Technical Reference Table 11-35 Internal disk drive connector signals for the Apple He Connector pin Signal Description 1 GND Ground 2 SEEKPHO Register select line CAO 3 GND Ground 4 SEEKPH1 Register select line CA1 5 GND Ground 6 SEEKPH2 Register select line CA2 7 GND Ground 8 SEEKPH3 Register write strobe LSTRB 9 -12V -12 volts 10 WRREQ' Write request 11 +5V +5 volts 12 +5V +5 volts 13 +12V +12 volts 14 EN1' Drive 1 select 15 +12V +12 volts 16 RDDATA Read data input 17 +12V + 12 volts 18 WRDATA Write data output 19 DISKACTY Disk activity light 20 WRPROT Write-protect input Table 11-36 Internal disk drive connector signals for the Apple lie Plus Connector pin Signal Description 1 GND Ground 2 SEEKPHO Register select line CAO 3 GND Ground 4 SEEKPH1 Register select line CA1 5 GND Ground 6 SEEKPH2 Register select line CA2 7 GND Ground 8 SEEKPH3 Register write strobe LSTRB CHAPTER 11 Hardware 381 Table 11-36 Internal disk drive connector signals for the Apple He Plus (continued) Connector pin Signal Description 9 EJECT Disk eject 10 WRREQ' Write data request 11 +5V +5 volts 12 HDSEL1' Register select line SEL 13 +12V +12 volts 14 INTENT Interna! disk drive enable 15 + 12V + 12 volts 16 RDDATA Read data input 17 +12V + 12 volts 18 WRDATA Write data output 20 csoinT Disk out signal Serial I/O Each Apple Ilc-family computer has built into it two 6551 asynchronous communication interface adapters (ACIA) and supporting input and output buffers for full-duplex serial communication. Figure 12-37 is a block diagram of the Apple He family serial ports. ACIA outputs are buffered by a 1448 quad line driver, and ACIA inputs are buffered by a 1489 quad line receiver. 382 Apple He Technical Reference Figure 11-37 Serial port circuits S\ AO. DSR' EXTINT * (From External Disk Drive Connector) A1 A4 Pin TxD TD1B. \ 6551 RTS' DTR1B*- 1 1488 ^DC. . ACIA RxD RD1B DCD' (Serial DSR1B 5/ V R/WT SER1 SER- Output PHO Buffer) IRQ* BCLK CTS' RESET fT 14M 74LS161 IRQ- PHO BCLK R/W SER- 1489 TxD (Serial TD2B ! 6551 RTS- \ Input DTR2B *~ 1 \DO~71/ ACIA RxD Buffer) RD2B V AO. SER2 DCD* DSR2B 5/ J A1 A5 DSR' (From Keyboard) V CTS' KSTRB RESET fJ Figure 11-38 is a detailed block diagram of the 6551 ACIA. The registers are described later in this section. CHAPTER 11 Hardware 383 Figure 11-38 6551 ACIA block diagram; (© 1978 by Synertek Inc.; used by permission) Transmit Control CTS* Transmit Transmit :> Data Register } Shift Register TxD IRQ* Status Interrupt Register DOD- Logic DER* RxC Control Baud Rate Register Generator XTAL1 ^ XTAL2 Receive Receive DB n Data Register c Shift Register RxD DB7 Data Bus Buffers c Command Receive :> Register Control DTR* -*- RTS* The ACIA pin assignments are shown in Figure 11-39 and described in Table 11-37. Note that the two 6551 ACIA chips are not used in exactly the same way—each one supports a different set of interrupts. 384 Apple He Technical Reference Figure 11-39 ACIA pinouts GND 1 ^ 28 R/W* A5 2 27 PHO SER" 3 26 IRQ* RESET- 4 25 D7 (N.C.) 5 24 D6 BCLK 6 23 D5 (N.C.) 7 22 D4 RTS* 8 21 D3 CTS' 9 20 D2 TxD 10 19 D1 (N.C.) 11 18 DO RxD 12 17 DSR' AO 13 16 DCD* A1 14 15 + 5V In the Apple He, the port 1 6551 reads external interrupts (EXTINT*) from the external disk drive connector on the 6551 chip's Data Set Ready (DSR) pin. This input is tied to +5 volts through a 3.3-kilohm pullup resistor. The EXTINT* signal is not available on the Apple He Plus. • Table 11-37 ACIA signal descriptions Pin Signal Description 1 GND Power and signal common ground 2 A4 Address line 4 to select serial port 1 A5 Address line 5 to select serial port 2 3 SER' Serial device select from GLU 4 RESET' Resets both serial ports 5 N.C. No connection 6 BCLK Baud rate clock from 1.84 MHz oscillator 7 N.C. No connection 8 RTS' Request to Send line 9 CTS' Clear to Send line (tied to ground) 10 TXD Transmit Data line 11 N.C. Not connected (Apple He) DTR Data Terminal Ready (Apple lie Plus) 12 RXD Receive Data line 13,14 A0,A1 Address lines 0 and 1 CHAPTER 11 Hardware 385 Table 11-37 ACIA signal descriptions (continued) Pin Signal Description 15 +5V +5 volt supply 16 DSR' Data Set Ready line 17 EXTINT* External intermpt (Apple He port 1) +5V Connected to +5V through a 33 KQ resistor (Apple He Plus port 1) KSTRB Keyboard strobe input (port 2) 18-25 D0-D7 8-bit data bus 26 IRQ' Intermpt Request line 27 PHO Phase 0 clock pulse 28 R/W* Read/write select input The back panel connectors for both serial ports are identical. In the original, UniDisk 3.5, and memory expansion versions of the Apple He they are 5-pin DIN type connectors. In the Apple lie Plus they are 8-pin mini-DIN type connectors. You can use the same cables with the serial connectors on the Apple lie Plus and the Macintosh; unlike the Macintosh, however, the Apple He serial ports do not support AppleTalk. The pin assignments for the original, UniDisk 3.5, and memory expansion versions are shown in Figure 11-40 and described in Table 11-38. The pin assignments for the Apple He Plus are shown in Figure 11-41 and described in Table 11-39. • Figure 11-40 Apple He serial port connectors 386 Apple He Technical Reference Table 11-38 Apple lie serial port connector signals Hn Signal Description 1 DTRIB Data Terminal Ready output DTR2B 2 TDIB Transmit Data output TD2B 3 GND Power and signal common 4 RDIB Read Data input RD2B 5 DSRIB Data Set Ready input DSR2B Figure 11-41 Apple He Plus serial port connectors Table 11-39 Apple He Plus serial port connector signals Pin Signal Description 1 DTRIB Data Terminal Ready output DTR2B 2 DSRIB Data Set Ready input DSR2B 3 TDIB Transmit Data output TD2B 4 GND Power and signal common 5 RDIB Read Data input RD2B 6 GND Power and signal common CHAPTER 11 Hardware 387 ACIA control register Figure 11-42 shows the bit assignments for the ACIA control register, which the hardware locates at address $C09B for serial port 1, and $C0AB for serial port 2. This register determines the number of data and stop bits the ACIA transmits and receives, and the clock source and transmission rate (baud) to use for data transfer. • Figure 1142 ACIA control r^^tcr (copyright ? io~Q *-••.• Synertek Inc.; used by permission) Port 1 - $C09B Port 2 - SCOAB Control Register Stop Bits Baud Rate Generator 0 = 1 stop bit 16X External Clock 1 = 2 stop bits 50 baud 1 stop bit if word length 75 = 8 bits and parity" Vh stop bits If word length 109.92 = 5 bits and no parity 134.58 150 Word Length . 300 Bit Data Word 6 5 Length 600 0 0 8 1200 0 1800 1 7 1 0 6 2400 1 1 5 3600 4800 Receiver Clock Source • 7200 0 = External receiver clock 9600 1 — Baud rate generator 19200 " 'This allows for 9-bit transmission (8 data plus parity). 7 6 5 4 3 2 1 0 Hardware Reset 0 0 0 0 0 0 0 0 Program Reset 388 Apple He Technical Reference ACIA command register Figure 11-43 shows the bit assignments for the ACIA command register, which the hardware locates al address $C09A for serial port 1, and at SCOAA for serial port 2. This register controls specific transmit and receive functions: parity checking, echoing input to output, allowing transmit and receive interrupts, and setting levels for the Data Terminal Ready and Request to Send signals. • Figure 11-43 ACIA command register (copyright © 1978 by Synertek Inc.; used by permission) Port 1 $C09A Port 2 SCOAA C o m m a n d Register Parity Check Controls . Oata Terminal Ready Bit 0 Disable receiver and all Operation 7 6 5 interrupts |DTR" high) Parity d i s a b l e d — n o parity bit 1 Enable receiver and all - - 0 generated, no parity bit received interrupts | D T R ' low) 0 0 1 Odd parity received and t r a n s m i t t e d Receiver Interrupt Enable 0 t 1 Even parity received and transmitted 0 IRQ' interrupt enabled from bit 3 MARK parity bit t r a n s m i t t e d , o l status register 1 0 1 received parity check disabled 1 IRQ* interrupt disabled SPACE parity bit t r a n s m i t t e d : 1 1 1 received parity check disabled . Transmitter Controls Bit Transmit RTS' Transmitter 3 2 Interrupt Level 0 0 Disabled High 0(1 N o r m a l Echo Mode 0 1 Enabled Low On lor Receiver 1 0 Disabled Low On 0 Normal 1 1 Disabled Low Transmit 8RK 1 Echo (bits 2 and 3 must be zero) 7 6 5 4 3 2 1 0 Hardware Reset 0 0 0 0 0 0 0 0 0 P r o g r a m Reset - - - 0 0 0 0 ACIA status register Figure 11-44 shows the bit assignments for the ACIA status register, which is hard-wired to address SC099 for serial port 1, and to $C0A9 for serial port 2. This register reports the condition of the transmit/receive register, errors detected during data transfer, and the level of the Data Carrier Detect, Data Set Ready, and Intermpt Request lines. CHAPTER 11 Hardware 389 Figure 1 1 4 4 ACIA status register (© 1978 by Synertek Inc.; used by permission) Port 1 SC099 7 6 5 4 3 2 1 0 Port 2 SC0A9 Status Set By Cleared By 0 - No error Parity errorf Self-clearing- * 1 ^ Error 0 - No error Framing errorf Self-clearing* * 1 = Error 0 - No error Overrunt Self-clearing*' 1 - Error Receive Data, 0 = Not full Reading receive Register full 1 = Full data register Transmit Data. 0 = Not empty Writing to transmit Register empty 1 = Empty data register Not resettable; 0 - DCD* low DCD* reflects DCD' 1 = DCD" high state Not resettable: 0 = DSR* low DSR* reflects DSR* 1 = DSR* high state 0 = No interrupt Reading status IRQ 1 = Interrupt register t No interrupt generated for these conditions. " ' Cleared automatically after a read of RDR and the next error-free receipt of data. 7 6 5 4 3 2 1 0 Hardware Reset 0 0 0 0 0 0 0 0 Program Reset 390 Apple He Technical Reference ACIA transmit/receive register Each ACIA uses the same address—SC098 for serial port 1, SC0A8 for serial port 2—as temporary storage for both transmission and reception of data. When the register is used for transmitting data, bit 0 is the leading bit to be transmitted; unused data bits are the high-order bits, which are ignored. When the register is used for receiving data, bit 0 is the first bit received; unused data bits are the high-order bits, which are set toO. Parity bits never appear in the receive data register; they are stripped off after being used for external parity checking. Mouse input This section describes how mouse movement and direction are detected and interpreted by the Apple He family. The mouse has a ball inside its housing that protrudes a small distance so that it turns when the mouse is pushed across a flat surface. Two wheels inside the housing, set al 90-degree angles to each other, are turned by the ball causing two disks to rotate. The disks have rectangular holes arranged near their edges, making them resemble the circular slide mounts used with stereoscopic slide viewers. The light from a tiny infrared emitter reaches a photoreceptor whenever one of the holes on the disk lies between them. An internal circuit in the mouse causes the resulting voltage to swing quickly to a 1 or a 0 value as soon as a certain threshold is crossed. The result is something approximating a square wave (see Figure 11-45) that varies directly with the speed of mouse movement. One of the square waves generated in this way indicates the X component (XO) of mouse movement; the other, the Y component (YO). CHAPTER 11 Hardware 391 Figure 11-45 Sample mouse waveform Movement Waveform ^mjuinmaruirLT^ Mouse Speed Under program control, eiLher the rising edge or the falling edge of each square wave can cause an intermpt, which the firmware handles by updating a counter. However, the program needs to know whether to add or to subtract 1 from a counter; that is, it needs lo know the direction of X or Y movement. There is a second infrared emitter/photoreceptor pair almost 180 degrees opposite the first pair for each disk. These pairs are positioned in such a way that the square waves they generate are approximately a quarter-wave offset from their respective movement waves (see Figure 11-46). These waveforms are called XI (X direction) and Y1(Y direction). 392 Apple lie Technical Reference Figure 11-46 Mouse movement and direction waveforms Mouse Movement 0—^ • . ^ Schottky: NO G r o u n d Level: NO Emitter Follower: NO CHAPTER 11 Hardware 399 Figure 11-52 Hand control circuits C06X * r SJK.'i a GAMESWO/MSW 8 :o i MUX ^ 220-470'..' OAPLlU': I) { 150 K 'J . PDL1/YOIR -T D7 1S0K'.~ POLO.'XMOVE SS 5 •»*•*—•**•••" DISCHARGE THRESHOLD £ " I . % IKtj „ 5 9 W | C07X. TRIG CTRL • c CTRL OUT S5 £ 9 GAMESWIMOUSEID1 i 3?4 . 512 TRIG OUT _TL £LI«—„ ^220-470'-' J 5V SJKD d£ DISCHARGE THRESHOLD CAPLllill IK '..' ^ 1 GND 4 70 f 80/40CColumn Swrtch 400 Apple lie Technical Reference TO* gjEMpniH 11H3JWVHD .•'.':'•'. (VUiCOl-'AOf (V"JUW8-'Ai'lL (vujo'Aas) (8l|OA) O O O I I O A j n t l u i • . S S> l - -.- s*o I 1—r i—: I., i •.-•/':~S ' li;")#^C^'|il^-*5 {VUJtaz'AS) ^ p i i ) D i p i i f i ; , j j o (VLU) 92 juejjno »ndu| S|EU8IS |OJIUOD puBH •gj-xi 3Jn3{j ~ The hand control inputs are connected to the timing inputs of an NE556 dual analog timer. Addressing SC07X sends a signal from MMU pin 22 that resets both timers and causes their outputs to go to 1 (high). A variable resistance of up to 150 kilohm connected between one of these inputs and the +5 volt supply controls the charging time of one of the two 0.022 microfarad capacitors. When the voltage on the capacitor passes a certain threshold, the output of the NE556 changes back to 0 (low). Programs can determine the setting of a variable resistor by resetting the timers and then counting time until the selected timer input changes from high to low. The resulting count is proportional to the resistance. A Important The only way to ensure correct paddle values is to make sure the output of the paddle you intend to read is low before you trigger the timer. Triggering the timer starts the charging cycle for the capacitor in each paddle circuit; the cycle for one may not be completed by the time you have read the other. If you retrigger or read the other paddle too soon (that is, in less than 3 ms), you gel a false value for it. A Memory expansion card Memory expansion card I/O is supported by firmware and by an internal connector mounted on the main logic board in the memory expansion Apple He and the Apple He Plus. The connector pins are identified in Figure 11-54 and Table 11-42. A Apple He Plus Due to the faster clock rate used in the Apple He Plus computer, the memory expansion card manufactured by Apple Computer, Inc., for use in the memory expansion Apple lie does not work in the Apple lie Plus. To add a memory expansion card to the Apple lie Plus, you must purchase a card made by another manufacturer specifically for the Apple lie Plus. However, the RAM chips on an Apple Memory Expansion Card can be used on a memory expansion card in the Apple He Plus computer, A 402 Apple lie Technical Reference For information on the Apple He Memory Expansion Card, refer to the Apple lie Memory Expansion Card Technical Reference. • Figure 11-54 Memory expansion card connector pinouts Pin Signal Pin Signal I DO 18 A9 2 Dl 19 A10 3 D2 20 All 4 D3 21 A12 5 D4 22 A13 6 D5 23 A15 7 D6 24 A15 8 D7 25 RESET IS* • IV 9 GND 26 RW 20 • • 19 10 GND 27 +5V 22* • 21 11 AO 2S +5V 24 • • 23 12 Al 29 PHO 26 • • 25 13 A4 30 GND 28 • • 27 14 A5 31 7M 30 • • 29 15 \6 32 GND 32 • • 31 16 A7 33 Q3 34 • • 33 17 A8 34 +5V CHAPTER II Hardware 403 T a b l e 1 1 4 2 Memory expansion card connector signals Pin Signal Description 1 DO System data line 0 2 Dl System data line 1 3 D2 System data line 2 4 D3 System data line 3 5 D4 System data line 4 6 D5 System data line 5 D6 System data line 6 8 D7 System data line 7 9 GND Ground 10 GND Ground 11 AO System address line 0 12 Al System address line 1 13 A4 System address line 4 14 A5 System address line 5 15 A6 System address line 6 16 A7 System address line 7 17 A8 System address line 8 18 A9 System address line 9 19 A10 System address line 10 20 All System address line 11 21 A12 System address line 12 22 A13 System address line 13 23 A14 System address line 14 24 A15 System address line 15 25 RESET' System reset 26 R/W* Read/write enable 27 +5V +5 volts 28 +5V +5 volts 29 PHO System clock 30 GND Ground 31 7M 7 MHz clock 32 GND Ground 33 Q6 Q 3 clock 34 +5V +5 volts 404 Apple He Technical Reference The Apple lie Plus computer has an additional internal expansion connector to provide additional signals for memory expansion cards. The pin assignments for this connector are shown in Figure 11-55, and the signals are described in Table 11-43. • Figure 11-55 Apple He Plus expansion connector Table 11-43 Apple He Plus expansion connector signals Pin Signal Description 1 RA14 ROM address 14 2 INH' Memory inhibit line 3 EN80* Enable auxiliary RAM 4 ROMENl* Enable ROM 5 A3 System address bit 3 6 A2 System address bit 2 7 BUSEN* Indicates valid access to MIG address space Apple lie Plus internal modem connector The Apple He Plus computer has an internal connector to support modems. The pin assignments for this connector are shown in Figure 11-56, and the signals are described in Table 11-44. CHAPTER 11 Hardware 405 Figure 11-56 Apple lie Plus internal modem connector Table 11-44 Apple lie Plus internal modem connector signals Pin Signal Description 1 -5V -5 volts 2 RXD Receive Data 3 TXD Transmit Data 4 DCD Data Carrier Detect 5 DTR Data Terminal Ready 6 DSR Data Signal Ready 7 GND Ground Note: All signals except -5V and GND are TTL levels Schematic diagrams Figure 11-57, on the following pages, is a set of schematic diagrams for the Apple lie. Figure 11-58 is a set of schematic diagrams for the Apple lie Plus. 406 Apple He Technical Reference Figure 11-57 Schematic diagrams for the Apple He 5 )ni|)uttT,Lir CK \ | ) [ ) l . l IHII|H||IT llh o Figure 11-57 Schematic diagrams for the Apple He (continued) 4*M4l?i*s j-* *i ii ••{••• 5 4 j At i s I * j £I GcTT li i i §3 S » n www II»ique K Li/ X£/ •VA- -VAr ! :. 410 Apple He Technical Reference c*o UCl — MO [3tPR ra H E R O N — - n u n 12—-JI-II,J«-'I CfJSCCKfM— L -H ji-n,j*-» tf>5lf*nn —— 11 jt-i>.,j»-# c-iitfrtAfO* -15 jiis.ja-ia ClJihJ*- * 1 5 — jtm (iiSCCKPKf—L — ji-li.Ja-t UJOTIM*—— " -JW — JZ-l4,J«H« (!'»"-:* CH5 "— -^ CM> I«IOT«- E13t i_- . --^ i'L-;, I» - a K. \|'jl'['l IKllpllltTllK | CD if*. •-» •O - o rn X e B. C. Ajjpk'liuiipiitiT.liK: 1 it*. I—» I 1 1 ~" "6. Aflili'G'iiij'uttrliK. n H > TZJ -a o 3 f t . AppJi'C/impntifljk. Figure 11-58 Schematic diagrams for the Apple lie Plus (continued) XT f*l >/), jsra «|S E *2II '•r mm L 1 ' < r ' 3 1 I ' - I - j | w ' * l ~ | * - " | * 1 — [ • ' " I I M I O '•^-vAA'—I TTTT ,,,5 5 " ««siirrt> s|„ J risi gg*** iTTPT •> H> ffl K3 3 - j / tf-l alt-1« 1*• i~^_J_jH> 21 LL 1 CHAPTER 11 Hardware 417 Figure 11-58 Schematic diagrams for the Apple lie Plus (continued) f""' M • 9 i f. •/ £3 • * • i • nnnn>- la Id o o s ^ i f J i n f; ft^llM£,A ' £ -; i t ills * rrrrrrrrn-n ^VYYYY iSii 3 a a a a a a a g s s| S L| M ? y\AA (wyyW V f-t-U-U-l llfli 2*«l")lj;;'","J 5 a = I'T li T T ' 1 ' I I 1 t) I? /•TH-"K '; ' i i rj rn P A y; j i". "i n U* * • T f ' I t) K Gt! Vvv f-Q v w AAA 55 n"lOTrnr Qfffl, - l i rl-; i . i i i . . . . -~rr;-;-] fflffi Hi LU-J-J M M M j f t T T J t I a s s|a ! ls U at si =! 3; 5. gS 2S | s : 418 Apple He Technical Reference Appendix A The 65C02 Microprocessor This appendix contains lhe data sheet for the NCR 65C02 microprocessor. It also describes the differences between the 6502 and 65C02 microprocessors, i 419 In the data sheet tables, execution times are specified in numbers of cycles. One cycle for the Apple He equals 0.978 microseconds. One cycle for the 65C02 in the Apple lie Plus running at 4 MHz equals 0.25 microseconds. If you want to write programs that execute on all computers in the Apple II series, make sure your code uses only the subset of 65C02 instructions present on the 6502. Differences between 6502 and 65C02 The data sheet in this chapter lists the new 65C02 instructions and addressing modes. This section supplements that information by listing the instructions for which the number of cycles or the results have changed from their 6502 counterparts. Differing cycle times In general, differences in cycle counts are significant only in time-dependent code, such as precise wait loops. Fortunately, instructions with changed cycle counts are few. Keep in mind, however, that the 65C02 in the Apple He Plus computer is capable of running at 4 MHz, nearly four times as fast as the 65C02 in earlier Apple He computers. Table A-l lists the 65C02 instructions whose number of instruction execution cycles is different from their number on the 6502. See "Addressing Modes" in the data sheet for an explanation of the modes. 420 Apple He Technical Reference Table A-l Cycle time differences Instruction/mode Opcode 6502 cycles 65C02 cycles ASL Absolute, X IE 7 6 DEC Absolute, X DE 7 6 INC Absolute, X FE 7 6 JMP (Absolute) 6C 5 6 LSR Absolute, X 5E 7 6 ROL Absolute, X 3E 7 6 ROR Absolute, X 7E 7 6 Differing instruction results The instructions that have different results from their 6502 equivalents are • BIT (in immediate mode) • JMP (indirect, when crossing a page boundary). The BIT instruction when used in immediate mode (code $89) leaves processor status register bits 7 (N) and 6 (V) unchanged on the 65C02. On the 6502, all modes of the BIT instruction have the same effect on the status register: the value of memory bit 7 is placed in status bit 7, and memory bit 6 is placed in status bit 6. However, all BIT instructions on both versions of the processor set status bit 1 (Z) if the memory location being tested contains a 0. If the JMP indirect instruction (code $60 references an indirect address location that spans a page boundary, the 65C02 fetches the high-order byte of the effective address from the first byte of the next page, while the 6502 fetches it from the first byte of the current page. For example, JMP ($02FF) gets ADL from location $02FF on both processors. On the 65C02, ADH comes from $0300 while on the 6502, ADH comes from $0200. APPENDIX A The 65C02 Microprocessor 421 Data sheet The rest of this appendix is copyright 1982, NCR Corporation, Dayton, Ohio, and is reprinted with their permission. In the data sheet, the notation for an active-low signal is an overbar instead of the asterisk used elsewhere in this manual. 422 Apple lie Technical Reference NCR NCR65C02 • GENERAL DESCRIPTION • PIN CONFIGURATION The NCR CMOS 6502 is an B-bit microprocessor which is soft- VSSC •0 iZJ *n ware compatible w i t h the NMOS 6 5 0 2 . The NCR65C02 hardware "o* C 3 39 H ] 3 ; 'OU interfaces w i t h all 6500 peripherals. The enhancements include out q i » = 3 50 ten additional instructions, expanded operational codes and «q t 4 "J . ca »<,..*, two new addressing modes. This microprocessor has all of the ad- at c — «* vantages of CMOS technology: low power consumption, increased 555 C 6 5 - N C CZ 7 *24 ZZ 0NC« ZIj noise i m m u n i t y and higher reliability. The CMOS 6502 is a low VDO C a U 1 DO power high performance microprocessor w i t h applications in the AC C I 9 1} =J°> consumer, business, automotive and communications market. A, C >» Enhanced software performance including 27 additional OP codes *• 1 16* *B Q 1} » t)«'« encompassing ten new instructions and t w o additional A9 \~2 i a » 21 P»" Al ] l addressing modes. AtO C 14 .'? H3 *I3 66 microprocessor instructions. AT 1 r ~ 30 71 Z 3 VSS 15 addressing modes. 178 operational codes. 1MHz. 2MHz operation. Operates at frequencies as low as 200 Hz for even lower power • NCR65C02 BLOCK DIAGRAM consumption {pseudo-static: stop during 8 2 high] Compatible w i t h NMOS 6500 series microprocessors. 64 Kbyte addressable memory. Interrupt capability. Lower power consumption. 4 m A @ 1MHz. +5 volt power supply. ( l l ) i i bidirectional data bus. Bus Compatible w i t h M 6 8 0 0 . Nonmaskable interrupt. AOOfttSl J 4 0 pin dual-in-line packaging. 8-bit parallel processing Decimal and binary arithmetic. Pipeline architecture. Programmable stack pointer. Variable length stack. Optional internal pullups for | R O Y . IRQ. SC, N M I and RES) Specifications are subject t o change w i t h o u t notice. Copyright © 1 9 8 2 by NCR Corporation, D a y t o n . Ohio, USA APPENDIX A The 65C02 Microprocessor 423 NCR65C02 " ABSOLUTE MAXIMUM RATINGS: IVDD = 5.0 V ± 5%. Vss • 0 V, TA = 0° to * 70°CI RATING SYMBOL VALUE UNIT SUPPLY V O L T A G E VDD -0.3 to+7.0 V INPUT V O L T A G E VIN - 0 . 3 to +7.0 V O P E R A T I N G TEMP. TA 0 to +• 70 °c STORAGE TEMP. T STG - 5 5 to • 150 °c • PIN FUNCTION PIN FUNCTION A 0 - A15 Address Bus DO - 0 7 Data Bus fEci' Interrupt Request ROY ' Ready Ml Memory Lock NMI' Non-Maskable Interrupt SYNC Synchronise Reset BB- so* Set Overflow No Connection NC R/W Read/Write VDD Power Supply I + 5V) VSS Internal Logic Ground 00 Clock Input 01,02 Clock Output •Th.s p.n has an optional .niefnai p u l l u p lO' a No C a n n e d c o n d n , o n • DC CHARACTERISTICS SYMBOL MIN. TYP. MAX UNIT Input High Voltage (to (IN) VlH V S S * 2- 4 - VDD V Input High Voltage RES, NM~i, RDY. LRQ, Data, S.O. V s s • 2.0 V Input Low Voltage 00 (IN) V|L v s s -0-3 - v s s + o-4 V RES, N M l , RDY, IRQ, Data, S.O. V S S + 0.8 V Input Leakage Current ( V | N = 0 to 5.25V, V D D = 5.25V) l|N With pullups -30 - +30 Without pullups +1 Q flA Three State (Off Statel Input Current I V | N = 0 . 4 t o 2 . 4 V , V c c • 5.25V) Data Lines 'TSI 10 MA Output High Voltage (IOH=-,0° /*Adc, VDD=4.75V SYNC, Data, A 0 - A I 5 , R/W) V0H V s s + 2.4 V Out Low Voltage ( l 0 i _ • 1.6mAdc, V n D • 4.75V SYNC. Data, A 0 - A 1 5 . R/W) VOL v s s + o-4 V — 4 mA Supply Current f = 1MHz IDD Supply Current f • 2MHz - 8 mA Capacitance C pF ( V , N - 0 , T A = 25°C. f • 1MHz) Logic - 5 Data 10 A 0 - A 1 5 , R/W, SYNC Cout - 10 C0O(INI 10 00 UN) 424 Apple He Technical Reference NCR6SC02 • A C C H A R A C T E R I S T I C S V D D • S.OV t 5%. T A = 0 ° C t o 70°C. Load • I T T L + 130 pF 1MHZ 2MHZ 3MHZ Parameter Symbol Mm Max Min Max Mm Max Unit Delay Time. Bo UN) to 02 (OUTI ( DL¥ - 60 - 60 20 60 nS Delay Time. Oi IOUT) to 0 j (OUT) 'OLVI -20 20 -20 20 -20 20 nS Cycle Time tCYC 10 5000' 0.50 5000" 0.33 5000' MS Clock Pulse Width Low tPL 460 - 220 - 160 - nS Clock Pulse Width High tPH 460 220 160 - nS Fall Time. Rise Time *F, Li 25 25 25 nS Address Hold Time 'AH 20 - 20 - 0 - nS Address Setup Time UDS - 225 - 140 - 110 nS Access Time : •osutl -1 REAO D A T A ymmMmiMMmiiimmmiiK wmrnii WRITE'DATA ~d > i p K* y SYNC 'IX x ML x X R D Y , LRQ N M l , RES X 5t SO I Note. All timing is referenced from a high voltage of 2.0 volts and a low voltage of 0.8 volts. • NEW INSTRUCTION MNEMONICS HEX MNEMONIC DESCRIPTION 80 BRA Branch relative always [ R e l a t i v e l 3A DEA Decrement accumulator ( A c c u m l 1A INA Increment accumulator [ A c c u m | DA PHX Push X on stack ( I m p l i e d ! 5A PHY Push Y on stack [ I m p l i e d ] FA PLX Pull X f r o m stack [ I m p l i e d ] 7A PLY Pull Y f r o m stack [ i m p l i e d ] 9C STZ Store zero [ A b s o l u t e ] 9E STZ Store zero [ A B S , X I 64 STZ Store zero IZero page] 74 STZ Store zero [ Z P G . X I IC TRB Test and reset m e m o r y bits w i t h accumulator [ A b s o l u t e ] 14 TRB Test and reset m e m o r y bits w i t h accumulator [Zero page] OC TSB Test and set m e m o r y bits w i t h accumulator [ A b s o l u t e ] 04 TSB Test and sei m e m o r y bits w i t h accumulator [Zero page] • ADDITIONAL INSTRUCTION ADDRESSING MODES HEX MNEMONIC DESCRIPTION 72 ADC A d d m e m o r y to ac c um ul ator w i t h carry ((ZPG) I 32 AND " A N D " m e m o r y w i t h accumulator [ I Z P G I I 3C BIT Test m e m o r y bits w i t h a c c u m u i a i o r [ A B S , X ] 34 BIT Test m e m o r y bits w i t h accumulator I Z P G , X | 02 CMP Compare m e m o r y and a c c u m u l a t o r I I Z P G I ] 52 EOR "Exclusive O r " m e m o r y w i t h accumulator [ ( Z P G ) ] 7C JMP J u m p I N e w addressing mode) [ A B S ( I N D . X ) ] B2 LDA Load accumulator w i t h m e m o r y [ I Z P G I I 12 ORA " O R " m e m o r y w i t h accumulator [(ZPG) I F2 SBC Subtract memory f r o m accumulator w i t h b o r r o w I I Z P G I ] 92 STA Store a c c u m u i a i o r in m e m o r y ((ZPG) 1 426 Apple He Technical Reference NCR65C02 • MICROPROCESSOR PROGRAMMING MODEL N | y | i l a l p T ; I f lc I ""ocEssofl STATUS ACCUMULATOR A INDEX REGISTER v " C A R R Y I i TRUE - ZERO 1 • RESULT ZERO Z ) INDEX REGISTER X • IH"C1 DISABLE 1 • DISABLE - D E C I M A L MODE 1 • TRUE _ [ PROGRAM COUNTER PC - B R K C O M M A N D 1 • BRK - O V E R F L O W I • TRUE j STACK POINTER S '! - N E G A T I V E 1 ' NEG • FUNCTIONAL DESCRIPTION Timing Control The timing control unit keeps track o l the instruction Accumulator cycle being monitored The unit is set to zero each time The accumulator is a general purpose 8-bit register that an instruction fetch is executed and «s advanced dt the stores the results of most arithmetic and logic operations, beginning of each phase one clock pulse for as many and in addition, the accumulator usually contains one of cycles as is required to complete the instruction. Each the t w o data words used in these operations. daia transfer which takes place between the registers de- pends upon decoding the contents of b o t h the instruc- Index Registers tion register and the timing control u n i t . There are two 8-bit index registers IX and Y ) , which Program Counter may be used to count program steps or to provide an The 16 bit program counter provides lhe addresses which index value to be used in generating an effective address. step the microprocessor through sequential instructions When executing an instruction which specifies indexed in a program. addressing, the CPU fetches the op code and the base address, and modifies the address by adding the index Each time the microprocessor fetches an instruction register to it prior to performing the desired operation. from program memory, the lower byte ot the program Pre- or post-indexing of indirect addresses is possible (see counter (PCLI >s placed on the low-order bits of the addressing modes), address bus and the higher byte of the program counter (PCHl is placed on the high order B bits. The counter is incremented each time an instruction or data is fetched Stack Pointer from program memory The stack pointer is an 8-bit register used to control the addressing of the variable-length stack on page one. The Instruction Register and Decode stack pointer is automatically incremented and decre- Instructions fetched from memory are gated onto the mented under control of the microprocessor to perform •nternai data bus. These instructions are latched into the stack manipulations under direction of either the program instruction register, then decoded, along w i t h timing and or interrupts (NMI and I R Q ) . The stack allows simple interrupt Signals, to generate control signals for the var- implementation of nested subroutines and multiple level ious registers. interrupts. The stack pointer should be initialized before any interrupts or stack operations occur. A r i t h m e t i c and Logic Unit ( A L U ! All arithmetic and logic operations take place in the Processor Status Register A L U including incrementing and decrementing internal The 8-bit processor status register contains seven status registers (except the program counter). The A L U has no flags. Some of the flags are controlled by the program, internal memory and is used only to p e r f o r m logical and others may be controlled both by the program and the transeni numerical operations. CPU. The 6500 instruction set contains a number of conditional branch instructions w h i c h are designed to allow testing of these flags (see microprocessor program- ming model I. APPENDIX A The 65C02 Microprocessor 427 NCR65C02 • ADDRESSING MODES f i f t e e n addressing modes are available to the user of the it establishes a destination tor the conditional branch. NCR65C02 microprocessor The addressing modes are The second byte of the instruction becomes the operand described in the following paragraphs which is an " O f f s e t " added to the contents of the pro gram counter when the counter is set at the next in- Implied Addressing | Implied| struction The range of the offset is - 1 2 8 to +127 In the implied addressing mode, the address containing bytes from the next instruction the operand is implicitly stated in the operation code of Zero Page Indexed Indirect Addressing K I N D , X)) the instruction. With zero page indexed indirect addressing (usually re- ferred to as indirect X} the second byte of the instruction Accumulator Addressing (Accuml •s added to the contents of the X index register, the This form of addressing .s represented w i t h a one byte carry is discarded The result of this addition points to a instruction and implies an operation on the accumu memory location on page zero whose contents is the low lator order eight bits of the effective address. The next mem- Immediate Addressing [Immediate] ory location m page zero contains the high order eight With immediate addressing, the operand is contained in bits of the effective address. Both memory locations the second byte of the instruction, no further memory specifying the high and low-order bytes of the effective addressing is required, address must be in page zero Absolute Addressing [Absolute! •Absolute Indexed Indirect Addressing [ A B S i I N D , X) 1 For absolute addressing, the second byle of the mstruc (Jump Instruction Only) tion specifies the eight low-order bits of the effective With absolute indexed indirect addressing the contents of address, while the third byte specifies the eight high order the second and third instruction bytes are added to the bits Therefore, this addressing mode allows access to the X register, The result of this addition, points to a memory total 64K bytes of addressable memory location containing the lower-order eight bits of the effective address. The next memory location contains Zero Page Addressing (Zero Page] the higher order eight bits of the effective address. Zero page addressing allows shorter code and execution times by only fetching the second byte of the instruction Indirect Indexed Addressing [ ( ( N O ) , Y) and assuming a zero high address byte The careful use This form of addressing is usually referred to as Indirect. of zero page addressing can result in significant increase Y The second byte of the instruction points to a mem in code efficiency. ory location m page zero. The contents of this memory location are added to the contents of the Y index regis- Absolute Indexed Addressing [ABS, X or ABS, Y | ter, the result being the low-order eight bits of the effec- Absolute indexed addressing is used in conjunction with tive address. The carry from this addition is added to the X or Y index register and is referred to as " A b s o l u t e , X , " contents of the next page zero memory location, the and " A b s o l u t e . Y . " The effective address is formed by result being the high-order eight bits of the effective adding the contents of X or Y to the address contained address. in the second and third bytes of the instruction. This mode allows the index register to contain the index ur •Zero Page Indirect Addressing ((ZPG)I count value and the instruction to contain the base In the zero page indirect addressing mode, the second address. This type of indexing allows any location refer byte of the instruction points to a memory location on encing and the index to modify multiple fields, resulting page zero containing the low-order byte of the effective in reduced coding and execution time. address. The next location on page zero contains the high-order byte of the effective address. Zero Page Indexed Addressing [ZPG, X or ZPG. Y l Zero page absolute addressing is used in conjunction Absolute Indirect A d d r e m n g [ ( A B S ) I w i t h the index register and is referred to as " Z e r o Page, J.Jump Instruction Only) X " or " Z e r o Page. Y " The effective address is calculated The second byte of the instruction contains the loworder by adding the second byte to the contents of the index eight bits of a memory location. The high-order eight register. Since this is a form of " Z e r o Page" addressing, bits of that memory location is contained in the third the content of the second byte references a location in byte of the instruction. The contents of the fully speci page zero. A d d i t i o n a l l y , due to the " Z e r o Page" address fied memory location is the l o w o r d e r byte of the effec- ing nature of this mode, no carry is added to the high' tive address. The next memory location contains the order eight bits ot m e m o r y , and crossing of page boun- high-order byte of the effective address which is loaded daries does not occur. into the 16 bit program counter, Relative Addressing [Relative] Relative addressing is used only w i t h branch instructions; NOTE: " = New Address Modes 428 Apple He Technical Reference NCR65C02 • SIGNAL DESCRIPTION Address Bus IA0-A15) Ready 1RDYI A 0 - A 1 5 forms a 16-bit address bus for memory and I/O This input allows lhe user to single-cycle the micropro- exchanges on the data bus. The o u t p u t of each address cessor on all cycles including write cycles. A negative line is T T L compatible, capable of driving one standard transition to the low state, during or coincident w i t h T T L load and 130pF. phase one I f l i l , will halt the microprocessor w i t h the out- put address lines r e j e c t i n g the current address being Clocks IBQ, a-i, and 02* fetched. This condition will remain through a subsequent 0Q is a T T L level input that is used to generate the inter- phase two (02) m which the ready signal is low. This fea- nal clocks m the 6502. T w o full level output clocks are ture allows microprocessor interfacing w i t h low-speed generated by the 6502. The 02 clock o u t p u t is in phase memory as well as direct memory access I O M A ) . w i t h 0Q- The Oi output pin U 180° out of phase w i t h flg. (See timing diagram.) Reset (RES) This input is used to reset the microprocessor. Reset must be held low for at least t w o clock cycles after Data Bus 1D0-O7) VDD reaches operating voltage from a power d o w n . A The data lines {D0-D7I constitute an 8-bit bidirectional positive t r a n s i t i o n on this pin will then cause an initiali- data bus used for data exchanges to and f r o m the device zation sequence to begin. Likewise, after the system has and peripherals. The outputs are three-state buffers been operating, a low on this line of at least t w o cycles capable of driving one T T L load and 130 p F . w i l l cease microprocessing activity, followed by initial- Interrupt Request (IRQ) ization after the positive edge on RES. This TTL compatible input requests that an interrupt When a positive edge is detected, there is an initialization sequence begin w i t h i n the microprocessor. The IRQ is sequence lasting six clock cycles. Then the interrupt sampled during 02 operation; if the interrupt flag in the mask flag is set, the decimal mode is cleared, and the pro- processor status register is zero, the current instruction gram counter is loaded w i t h the restart vector f r o m loca- is completed and the interrupt sequence begins during tions FFFC How byte) and F F F D (high b y t e l . This is 0 i . The program counter and processor status register the start location for program c o n t r o l . This input should are stored in the stack, The microprocessor w i l l then set be high in normal operation. the interrupt mask flag high so that no further IRQs may occur. At the end of this cycle, the program counter low will be loaded from address F F F E , and program Read/Write (R/W) counter high from location F F F F , transferring program This signal is normally in the high state indicating that control to the memory vector located at these addresses. the microprocessor is reading data from memory or I/O The RDY signal must be in the high state for any inter- bus. In the low state the data bus has valid data from the rupt to be lecogmzed. A 3K ohm external resistor should microprocessor to be stored at the addressed memory be used for proper wire OR operation. location. Set Overflow ISO) Memory Lock (ML) A negative transition on this line sets the overflow bit in In a multiprocessor system, the M L o u t p u t indicates the lhe status code register. The signal is sampled on the trail- need to defer the rearbitration of the next bus cycle to ing edge of 0 j . ensure the integrity of read-modify-write instructions. Synchronize (SYNCI M L goes low during A S L . DEC. INC. LSR. R O L . ROR. This o u t p u t line is provided to identify those cycles dur- TRB, TSB memory referencing instructions. This signal ing which the microprocessor is doing an OP CODE is low for the modify and write cycles. fetch. The SYNC line goes high during 0 | of an OP CODE Non-Maskable Interrupt { N M D fetch and stays high for the remainder of that cycle. If A negative going edge on this input requests that a non the RDY line is pulled low during the 01 clock pulse m maskable interrupt sequence be generated w i t h i n the which SYNC went high, the processor w i l l stop in its microprocessor, The N M I is sampled during 02- t n e c u r current state and w i l l remain in the state u n t i l the R D Y rent instruction is completed and the interrupt sequence line goes high. In this manner, the SYNC signal can be begins during 0*). The program counter is loaded w i t h used to control RDY to cause single instruction execu- the interrupt vector from locations F F F A (low byte) tion. and F F F B (high byte), thereby transferring program con trol to the non-maskable interrupt routine. Note: Since this interrupt is n o n m a s k a b l e , another NMI can occur before the first is finished. Care should be taken when using N M I t o avoid this. APPENDIX A The 65C02 Microprocessor 429 NCR65C02 • INSTRUCTION SET — ALPHABETICAL SEQUENCE AOC Add Memory 10 Accumulato< with Carry LDX Load Index X with Memory AND A N D " Memory with Accumuiaior LDY Load Index Y with Memory ASL Sh.li One Bn U M LSR Shift One Bn Right BCC Branch an Carry Clear NOP No Operation BCS Branch on Carry Set ORA " O R " Memory with Accumuiaior BEQ Branch on Result Zero PHA Push Accumulator or* Suck BIT Test Memory Bill with Accumulator PHP Push Processor Status on Stack BMI Branch on Result Minus * PHX Push Index X an Stack BNE Branch on Result *iol Zero • PHY Puih index Y on Stacx BPL Branch an Remit Plui PLA Pull Accumulator from Stack ' B R A Branch Always PLP Pull Processor Status from Slack BRK Force Breik * PLX Pull Index X from Stack BVC Branch on Overflow Clear • PLY Pull Index V from Stack BVS Branch on Overflow Sei ROL Rotaie One Bit Left CLC Clear Carry Flag ROR Rotate One B't Right CLD Clear Oeomai Mode RTI Return from Interrupt CLI Clear Interrupt Disable Bit RTS ReTurn from Subroutine CLV Clear Overflow Flag SBC Subtract Memory Iram Accumulator with Borrow CMP Compare Memory and Accumuiaior SEC Sffl Carry Flag CPX Compart Memory and Index X SED Set Oecimal Mode CPY Compare Memory and Index V SEI Set Interrupt Disable Bn • DEA Decrement Accumulate STA Store Accumulator m Memory DEC Decrement by One STX Store Index X -n Memory OCX Decrement Index X by One STY Store Index Y d. X 1 * 3 a dON rK-»_ il- 0 esi Zlvs- AQT : N c V 39 I » »9 1ICIr : l 7 N | C 9 3-J 9 9* s 9 9 3 IC 9 33 II ift . 1 • ft 3 N I VMl Z N Z Vi ; V - 1 • » ' VNl w03 7 M 5 rs c • 65 C » OS I » 95 Z *!ii 19 ir 1 St E a* E * i.r r . IA A v j « 0 3 A 30 7 N ilk A 30 X30 Z N ; VD I f l X X30 7 N I. 9 3 0 z 9 W : s 93 c 9 33 111 r"-. 1 rt 3 3 0 V30 2 N z vr » . 1 » V30 A-13 3 2 N iO .' ! 3-j 03 rt A A d 3 X.O 5 7 It .-. X xa3 • •* N H t 39 09 4rtl 5 7 •• : S C O t r u t • 00 z • M i 5 10 1 1= 93 c •03 63 III rt V a CO AID 0 :N C E ft . 0 ft13 •ID D Z • • 0 no 013 0 ( •a 0 . 0 0T3 313 0 eti 3.0 3T3 D z a; (El i - A j-y-ttrt'fl SAB DAB z 1 05 •CI 0*ft 1' y->«»'8xue 3AB oa vbi 1 £ 06 i* ' * " " * - ^ " 8 TUB i "Wl 1 Z 01 u O - N i- ->-*>-e I d B 3*B I : oo 111 0 - 7 1- * w « ' 8 3NB irtfl c t oc IE' !.•*/*• n*>f/8 'rlH ill 2 .•*..„ c t 3t I p|*I c cf t c •- D£ Ct » 15 VI r V V V 1IB ma z Z Oi |*i 1-7 r W ' 1 D3B sot Z Ofl IE. lOl'MMIil S38 33B I : w. |£i 0O.*J>-«'8 338 isv 3 2 H c 9 II • g 91 1 z VO 90 [ 9 3 0 « TSV 2 3CV 3 2 3-vn D 2 1 0 • HI 5 A N C 9 A N * - *c Z: t » « t » a; ao 1 - ao» • aon - * o * • n » v3 0 » NDHVH3#C V*IA1VV ON* 3NTT O K C r d i I i l l (.1 1 S3003 STliriS oa2> i> O N I I SSVI IAU A SflV I I « » A 142 * 042 A j ix j a j n a ••in 3 3 v 1 r 11 | | 3ivt0 U0TS130Uai sav 1 ONM | O N I ; | m OU3Z | O S f l * 1 3nni 81N3W3Hin03U AdOW3W QNV '3WI1 N O I i n 0 3 X 3 'S3QO0 lVNOUVUBdO S03S9U3N Appendix B Address Map This appendix lists all important RAM and hardware locations in address order and briefly describes them. The tables in this appendix list addresses in either two or three forms: the hexadecimal form (preceded by a dollar sign) for use in assembly language; the decimal form for use in Applesoft BASIC; and (for numbers greater than 32,767) the complementary decimal value for use in Apple Integer BASIC. • 433 Page $00 Table B-l lists the zero-page addresses in hexadecimal and decimal form, followed by symbols denoting the firmware or system software that uses them. • M denotes the Monitor. • A denotes Applesoft BASIC. • / denotes Integer BASIC. • D denotes DOS 3.3. • Pdenotes ProDOS. Locations whose contenLs ProDOS saves and restores have a P in parentheses, indicating that ProDOS has no net effect on them. 434 Apple He Technical Reference Table B-l Page $00 use Hex Dec Used by Hex Dec Used by $00 0 A $25 37 M $01 1 A $26 38 M D $02 2 A $27 39 M D $03 3 A $28 40 M D $04 4 A $29 41 M D $05 5 A $2A 42 M D $06 6 $2B 43 M D $07 7 $2C 41 M D $08 8 $2D 45 M D $09 9 $2E 46 M D $0A 10 A $2F 47 M D SOB 11 A $30 -i8 M soc 12 A $31 49 M $0D 13 A $32 50 M $0E 14 A $33 51 M $0F 15 A $34 52 M $10 16 A $35 53 M D $11 17 A $36 51 M D $12 18 A $37 55 M D $13 19 A $38 56 M D $14 20 A $39 57 M D $15 21 A $3A S3 M P $16 22 A S3B 59 M P $17 23 A $3C 60 M P $18 24 A $3D 61 M P $19 25 $3E 62 M D P $1A 26 $3F 63 M D P $1B 27 $40 64 M D (P) $1C 23 $41 65 M D(P) $1D 29 $42 65 M D (P) $1F 31 $43 67 M D (P) APPENDIX B Address Map 435 Table B-l Page $00 use (continued) Hex Dec Used by Hex Dec Used by $44 68 M D (P) $67 103 A D $45 69 M D (P) $68 101 A D $46 70 M D SCP) $69 105 A D $47 71 M D (P) $6A 106 A D $48 72 M D (P) $6B 107 A $49 73 M (P) $6C 108 A $4A 74 D (P) $6D 109 A $4B 75 D (P) $6E 110 A $4C 76 D (P) $6F 111 A D $4D 77 D (P) $70 112 A D $4F 79 M $71 113 A $55 85 M A $72 114 A $56 86 A $73 115 A $57 87 A $74 116 A $58 83 A S75 117 A $59 89 A $76 118 A $5A 90 A $77 119 A S5B 91 A $78 120 A $5C 92 A $79 121 A $5D 93 A $7A 122 A $5E 94 A $7B 123 A $5F 95 A $7C 124 A $60 96 A $7D 125 A $61 97 A $7E 126 A $62 98 A $7F 127 A $63 9) A $80 128 A $64 100 A $81 129 A $65 101 A S82 130 A $66 102 A $83 131 A 436 Apple He Technical Reference Table B-l Page $00 use (continued) Hex Dec Used by Hex Dec Used by $84 132 A I $A2 162 A I $85 133 A I $A3 163 A I $86 154 A I $A4 164 A I $87 135 A I $A5 165 A I $88 136 A I $A6 166 A I $89 137 A I $A7 167 A I $8A 138 A 1 $A8 168 A I $8B 139 A 1 $A9 W) A I $8C 140 A I $AA 170 A I $8D 141 A 1 $AB 171 A I $8E 142 A I $AC 172 A I $8F 143 A I $AD 173 A I $90 144 A I $AE 174 A I $91 145 A I $AF 175 A I D $92 146 A I $B0 176 A I D $93 147 A I $B1 177 A I $94 148 A I $B2 178 A I $95 149 A I $B3 179 A I $96 150 A I $B4 180 A I $97 151 A I $B5 181 A I $98 152 A I $B6 182 A 1 $99 153 A I $B7 183 A I $9A 154 A I $B8 184 A I $9B 155 A I $B9 185 A I $9C 156 A 1 $BA 186 A I $9D 157 A I $BB 187 A I $9E 158 A I $BC 188 A I S9F 159 A I $BD 189 A I SAO 160 A I $BE 190 A I $A1 161 A I $BF 191 A I APPENDIX B Address Map 437 Table B-l Page $00 use (continued) Hex Dec Used by Hex Dec Used by $C0 192 A I $E0 224 A $C1 193 A I $E1 225 A $C2 194 A I $E2 226 A $C3 195 A I $E3 227 $C4 196 A 1 $E4 223 A $C5 197 A I $E5 229 A $05 198 A I $E6 230 A $C7 199 A I $E7 231 A $C8 200 A I $E8 232 A $C9 201 A I $E9 233 A $CA 202 A I D $EA 234 A $CB 203 A 1 D $EB 235 $CC 204 A I D $EC 236 $CD 205 A I D $ED 237 $CE 206 I SEE 238 $CF 207 I $EF 239 $D0 208 A I $F0 240 A $D1 209 A I $F1 241 A $D2 210 A I $F2 242 A $D3 211 A I $F3 243 A $D4 212 A I $F4 244 A $D5 213 A I $F5 245 A $D6 214 I $F6 246 A $D7 215 I $F7 247 A $D8 216 A I D $F8 248 A $D9 217 A I $F9 249 $DA 218 A I $FA 250 $DB 219 A I $FB 251 $DC 220 A I $FC 252 $DD 221 A I $FD 253 $DE 222 A 1 $FE 254 $DF 223 A I $FF 255 438 Apple He Technical Reference Page $03 Most of page $03 is available for small machine-language programs. The built-in Monitor uses the top 16 addresses of page $03, as shown in Table B-2; the XFer routine uses locations $03ED and S03EE. If you are using DOS or ProDOS, it also uses the 32 locations $03D0 through $03EF. • Table B-2 Page $03 use Hex Dec Use $03F0 1008 Address of the subroutine that handles BRK instructions (normally SFA59) $03F1 1009 $03F2 1010 Reset vector S03F3 1011 S03F4 1012 Power-up byte (see text) $03F5 1013 Jump instruction to Applesoft &-command $03F6 1014 handler (initially $4C, $58, SFF) $03F7 1015 S03F8 1016 Jump instruction to user Control-Y command $03F9 1017 handler S03FA 1018 $03FB 1019 Jump instruction to NMI interrupt handler $03FC 1020 (not used by Apple He) $03FD 1021 S03FE 1022 Address of user IRQ interrupt handler S03FF 1023 APPENDIX B Address Map 439 Screen holes One result of the way the Apple Ilc-family hardware maps display memory on the screen is that groups of 8 memory addresses are left over in 16 areas of the text and Lo-Res graphics display pages—8 areas in main RAM and 8 in auxiliary RAM. The firmware uses for these 128 bytes are shown in Tables B-3 and B-4. A Apple He Plus The memory expansion Apple He and the Apple lie Plus use some of the Memory expansion screen holes differently than earlier Apple He computers. Where they differ, the memory expansion/Apple lie Plus ROM assignments are given in braces (! 1) following the original and UniDisk 3.5 assignments, A Table B-3 Main memory screen hole allocations Hex Dec Description $0478 1144 Mouse port: low byte of clamping minimum $0479 1145 Reserved for serial port 1 $047A 1146 Reserved for serial port 2 S047B 1147 Reserved $047C 1148 Low byte of X coordinate (Reserved) $047D 1149 Reserved for mouse port S047E 1150 Reserved S047F 1151 Reserved {Low byte of X coordinate} $04F8 1272 Mouse port: low byte of clamping maximum $04F9 1273 Reserved for serial port 1 S04FA 1274 Reserved for serial port 2 S04FB 1275 Reserved S04FC 1276 Low byte of Y coordinate (Owner of serial buffer (if any)) $04FD 1277 Reserved for mouse port $04FE 1278 Reserved $04FF 1279 Owner of serial buffer (if any) (Low byte of Y coordinate) 440 Apple He Technical Reference Table B-3 Main memory screen hole allocations (continued) Hex Dec Description $04 FD 1277 Reserved for mouse port $04 FE 1278 Reserved $04 FF 1279 Owner of serial buffer (if any) (Low byte of Y coordinate) $0578 1400 Mouse port: high byte of clamping minimum $0579 1401 Port 1 printer width (1-255; 0 = unlimited) $057A 1402 Port 2 line length (1-255; 0 = unlimited) S057B 1403 Cursor horizontal position (80-column display) S057C 1404 High byte of X coordinate (Pointer to next storage location for keyboard buffer) $057D 1405 Reserved for mouse port $057E 1406 Reserved $057F 1407 Pointer to next storage location for serial buffer (High byte of X coordinate) $05F8 1528 Mouse port: high byte of clamping maximum $05F9 1529 Port 1 temporary storage location $05FA 1530 Keyboard buffer control $05FB 1531 Reserved S05FC 1532 I Iigh byte of Y coordinate (Pointer to next storage location for keyboard buffer) S05FD 1533 Reserved for mouse port S05FE 1534 Reserved S05FF 1535 Pointer to next storage location for keyboard buffer (High byte of Y coordinate) $0678 1656 Reserved $0679 1657 Indicates when port 1 firmware is parsing a command $067A 1658 Indicates when port 2 firmware is parsing a command $067B 1659 Reserved $067C 1660 Mouse port: reserved (Pointer to next retrieval location for serial buffer) S067D 1661 Reserved for mouse port S067E 1662 Reserved $067F 1663 Pointer to next retrieval location for serial buffer (Mouse port: reserved) $06F8 1784 Reserved $06F9 1785 Current port 1 command character $06FA 1786 Current port 2 command character APPENDIX B Address Map 441 Table B-3 Main memory screen hole allocations (continued) Hex Dec Description $06FB 1787 Reserved $O6FC 1788 Mouse port: reserved (Pointer to next retrieval location for keyboard buffer) $06FD 1789 Reserved for mouse port $O6FE 1790 Reserved $06FF 1791 Pointer to next retrieval location for keyboard buffer (Mouse port: reserved) $0778 1912 $n0 = current active port number x 16 $0779 1913 Port 1 flags for echo and auto line feed S077A 1914 Port 2 flags for each and auto line feed $077B 1915 Reserved $077C 1916 Mouse port status byte (Reserved) $077D 1917 Reserved for mouse port $077E 1918 Reserved $077F 1919 Reserved (Mouse port status byte) $07F8 2040 Owner of $C800-$CFFF (SC3, video) S07F9 2041 Port 1 current printer column $07FA 2042 Port 2 current line position $07FB 2043 Reserved S07FC 2044 Mouse port mode byte (Reserved) S07FD 2045 Reserved for mouse port S07FE 2046 Reserved $07FF 2047 Reserved (Mouse port mode byte) 442 Apple lie Technical Reference Table B-4 Auxiliary memory screen hole allocations Hex Dec Description $0478 1144 Initial port 1 ACIA control register values ($9E) $0479 1145 Initial port 1 ACIA command register values ($0B) $047A 1146 Initial port 1 characteristics flags ($40) $047B 1147 Initial port 1 printer width ($50) $047C 1148 Initial port 2 ACIA control register values ($16) S047D 1149 Initial port 2 ACIA command register values (SOB) S047E 1150 Initial port 2 characteristics flags ($01) S047F 1151 Initial port 2 line length ($00) $04F8 1272 through Reserved $04FF 1279 $0578 1400 through Reserved S057F 1407 $05F8 1528 through Reserved $05FF 1535 $0678 1656 through Reserved $067F 1663 S06F8 1784 through Reserved S06FF 1791 $0778 1912 through Reserved $077F 1919 S07F8 2040 through Reserved $07FF 2047 APPENDIX B Address Map 443 The hardware page ($C0) Tables B-5 through B-9 list all the hardware locations available for use in the Apple He family. These tables have a column at the left that is not present in other tables in this appendix. This column, labeled RW, indicates the action to take at a particular location. • y? m e a n s read. • RR means read twice in succession. • #7means read the byte and then check bit 7; in the use column, "See if..." refers to the condition represented by bit 7=1, unless otherwise specified. Bit 7 has a value of $80, so if the contents of the location are greater than or equal to $80, the bit is on. Another way to test bit 7 (the sign bit) is with a BIT instruction, followed by BPL (bit 7 was 0) or BMI (bit 7 was 1). • R/W means to either read or write. For writing, the value is unimportant. • Wmeans to write only. The value is unimportant. • A'means not to read or write because the location is reserved. An address of the form $CO0n refers to the 16 locations from $C000 through $C0OF. Labels, when they are shown, are simply memory aids. Some of them correspond to the labels at those addresses in the firmware, while others do not. Your program must assign a label for it anyway. • Table B-5 Addresses SC000-$C03F KW Hex Dec Neg dec Label Use R SCOOn KStrb Read keyboard data (bits 0-6) and strobe (bit 7) W SCOOO 49152 -16384 80Store Off: Page2 switches Page 1 and 2 W SC001 49153 -16383 80Store On: Page2 switches Page 1 and IX w $C002 49154 -16382 RAMRd Off: Read main 48K memory w $0004 49156 -16380 RAMWrt Off: Write in main 48K memory w $0005 49157 -16379 RAMWrt On: Write in auxiliary 48K memory w SC006 49158 -16378 Reserved w $C007 49159 -16377 Reserved w $0003 49160 -16376 AltZP Off: Use main P0, PI, bank-switched RAM 444 Apple He Technical Reference Table B-5 Addresses $C0OO-$C03F (continued) RW Hex Dec Neg dec Label Use W SO009 49161 -16375 AltZP On: Use auxiliary PO, PI, bank-switched RAM w $C00A 49162 -16374 Reserved w $C00B 49163 -16373 Reserved w $O00C 49161 -16372 8OC0I Off: 40-column display W $C00D 49165 -16371 80Cd On: 80-column display w $C00E 49166 -16270 AltChar Off: Display primary character set w $C00F 49167 -16369 AltChar On: Display alternate character set w SCOln Clear keyboard strobe (SCOOn bit 7) R7 SC010 49168 -16368 AKD See if any key now down; clear strobe R7 $0011 49169 -16367 RdBnk2 Seeifusing$D000bank2(orl) R7 $C012 49170 -16366 RdLCRAM See if reading RAM (or ROM). R7 $C013 49171 -16365 RdRAMRd See if reading auxiliary or main 48K memory R7 $0014 49172 -16364 RdRAMWrt See if writing auxiliary or main 48K memory R SC015 49173 -16363 RstXInt Reset mouse XO interrupt R7 SC016 49174 -16362 RdAltZP See if auxiliary PO, PI and bank-switched RAM R $0317 49175 -16361 RstYInt Reset mouse Y interrupt R7 SC018 49176 -16360 Rd80Store See if 80Store on (or off) R7 $0319 49177 -16359 RstVBl Read and then reset VBL interrupt flag R7 $C01A 49178 -16358 RdTEXT See if text (or graphics) R7 $C01B 49179 -16357 RdMIXED See if mixed mode switch on R7 SO01C 49180 -16356 RdPage2 See if Page 2/ IX selected R7 $C01D 49181 -16355 RdHiRes See if Hi-Res switch on R7 $031E 49182 -16354 RdAltChar See if alternate character set (or primary) R7 $C01F 49183 -16353 RdSOCd Read 8OC0I switch (l=on) R/W $C020 49184 -16352 through Toggle between main and auxiliary ROM R/W SC02F 49199 -1633 W SC030 49200 -16336 Reserved R $C030 49200 -16336 Toggle speaker N SC031 49201 -16335 through Reserved (read and write) N SC03F 49215 -16321 APPENDLXB Address Map 445 Table B-6 Addresses SC040-SC05F HW Hex Dec Ncg dec Label Use R7 $0040 49216 -16320 RdXYMsk See ifXO/YO mask set R7 $0041 49217 -16319 RdVBlMsk See if VBL mask set R7 $C042 49218 -16318 RdXOEdge See if interrupt on falling XO edge R7 $0043 49219 -16317 RdYOEdge See if interrupt on falling YO edge N SC044 49220 -16316 Reserved N $0045 49221 -16315) Reserved N $0046 49222 -16314 Reserved N SO047 49223 -16313 Reserved R $0048 49224 -16312 RstXY Reset XO/YO interrupt flags N $0049 49225 -16311 Reserved N $C04A 49226 -16310 Reserved N $C04B 49227 -16309 Reserved N S004C 49228 -16308 Reserved N SC04D 49229 -16307 Reserved N SC04E 49230 -16306 Reserved N SC04F 49231 -16305 Reserved R/W $0050 49232 -16304 Text Off: Graphics display R/W $0051 49233 -16303 Text On: Text display R/W SC052 49234 -16302 Mixed Off: Text or graphics only R/W SC053 49235 -16301 Mixed On: Combination text and graphics R/W $0354 49236 -16300 Page2 Off: Use Page 1 R/W SC055 49237 -16299 Page2 On: Display Page 2 (80Store off); store to Page lX(80Storeon) R/W $0056 49238 -16298 HiRes Off: Lo-Res R/W $0057 49239 -16297 HiRes On: Hi-Res; Double Hi-Res If 8OC0I and DHiRes on N $0058 49240 -16296 Reserved if IOUDis on ($C07E bit 7=1) R/W DisX Disable (mask) mouse XO/YO interrupts N $0059 49241 -16295 Reserved if IOUDis on R/W EnbXY Enable (allow) mouse XO/YO interrupts N $C05A 49242 -16294 Reserved if IOUDis on R/W DisVBl Disable (mask) VBL interrupts N $C05B 49243 -16293 Reserved if IOUDis on R/W EnVBl Enable (allow) VBL interrupts N $C05C 49244 -16292 Reserved if IOUDis on R/W XOEdge Interrupt on rising edge of XO 446 Apple He Technical Reference Table B-6 Addresses $CO4O-$C05F (continued) KW Hex Dec Ncg dec Label Use N $C05D 49245 -1629 Reserved if IOUDis on R/W XOEdge Interrupt on falling edge of XO R/W $C05E 49246 -16290 DHiRes If IOUDis on: Set Double Hi-Res R/W YOEdge If IOUDis off: Interrupt on rising YO R/W SC05F 49247 -16289 DHiRes If IOUDis on: Clear Double Hi-Res R/W YOEdge If IOUDis off: Interrupt on falling YO Table B-7 Addresses $C060-$C07F KW Hex Dec Neg dec Label Use w $C06x Reserved (write) R7 $C060 4924 -16288 Rd&OSw See if 80/40 switch down (1 = 40) R7 $0361 49249 -16287 RdBtnO See if mouse button/paddle button 0/ Command (Open-Apple) key pressed (1 = pressed) R7 $0062 49250 -16286 RdBtnl See if paddle button l/Option (Solid Apple) pressed (1 = pressed) Iff $0063 49251 -16285 Rd63 See if mouse button not pressed (0 = pressed) R7 $0364 49252 -16284 PdlO Paddle 0 analog input IV $0365 49253 -16283 Pdll Paddle 1 analog input R7 $0366 49254 -16282 MouXl See if mouse XI (direction) is high B7 $0367 49255 -16281 MouYl See if mouse Yl (direction) is high N $0368 49256 -16280 through Reserved (write and read) N $C06F 49263 -16273 R/W $C07x Trigger paddle timer; reset VBlInt; however, $C071-$C07D are reserved R/W $0070 49264 -16272 PTrig Designated trigger or reset location N $0071 49265 -16271 through Reserved N $C07D 49277 -16259 APPENDIX B Address Map 447 Table B-7 Addresses $C060-$C07F HW Hex Dec N'eg dec Label Use R7 $C07E 49278 -16258 RdlOUDis See if IOUDis on; trigger paddle timer; reset VBlInt W IOUDis On: Enable access to DHiRes switch; disable SC058-SC05F IOU access R7 $C07F 49279 -16257 RdDHiRes See if DHiRes off W IOUDis Off: Disable access to DHiRes switch; enable SC058-SC05F IOU access Table B-8 Addresses $C08O-$C0AF KW Hex Dec Neg dec Label Use R $0380 49280 -16256 Read RAM; no write; use $D000 bank 2 RR $0031 49281 -16255 Read ROM; write RAM; use SD000 bank 2 R $0382 49282 -16254 Read ROM; no write; use SDOOO bank 2 RR $0083 49283 -16253 Read and write RAM; use $D000 bank 2 N $0384 49284 -16252 Reserved N $0385 49285 -16251 Reserved N $0386 49286 -16250 Reserved N $0087 49287 -16249 Reserved R $0038 49288 -16248 Read RAM; no write; use $D000 bank 1 RR $0389 49289 -16247 Read ROM; write RAM; use $D0OO bank I R SC08A 49290 -16246 Read ROM; no write; use $D000 bank 1 RR SCOSB 49291 -16245 Read and write RAM; use $D000 bank 1 N $O08C 49292 -16244 Reserved N $C08D 49293 -16243 Reserved N $C08E 49294 -16242 Reserved N $C08F 49295 -16241 Reserved N $0390 49296 -16240 through Reserved N $0397 49303 -16233 R/W $0398 49304 -16232 Port 1 ACIA transmit/receive register R/W $0399 49305 -16231 Port 1 ACIA status register R/W $C09A 49306 -16230 Port 1 ACIA command register R/W $C09B 49307 -16229 Port 1 ACIA control register 448 Apple He Technical Reference Table B-8 Addresses $C080-$COAF (continued) KW Hex Dec Ncg dec Label Use N SC09C 49308 -16228 through Reserved N SC09F 49311 -16225 N SCOAO 49312 -16224 through Reserved N SC0A7 49319 -16217 R/W $C0A8 49320 -16216 Port 2 ACIA transmit/receive register R/W $C0A9 49321 -16215 Port 2 ACIA status register R/W $C0AA 49322 -16214 Port 2 ACIA command register R/W $C0AB 49323 -16213 Port 2 ACIA control register N $03AC 49324 -16212 through Reserved N SCOAF 49327 -I6209 Table B-9 Addresses $C0BO-$C0FF RW Hex Dec Ncg De Label Use N $COB0 49328 -16208 through Reserved N $C0BF 49343 -16193 N $0300 49344 -16192 through Reserved N $C0CF 49359 -16177 N $C0D0 49360 -16176 through Reserved N $C0DF 49375 -16161 N $O0E0 49376 -16160 through Reserved N SCOEF 49391 -16145 N $C0F0 49392 -16144 through Reserved N $C0FF 49407 -16129 APPENDIX B Address Map 449 Appendix C Operating Systems and Languages This appendix is an overview of the characteristics of operating systems and languages when run on Apple Ilc-family computers. It is not intended to be a complete description. For more information, refer to the manuals that are provided with each product. • 451 Operating systems This section discusses the operating systems with which the Apple He family works. CP/M—and any other operating system that requires an interface card—does not work on the Apple He family. ProDOS ProDOS is the preferred disk operating system for Lhe Apple He family. It supports all of the hardware and firmware features of all versions of the Apple He. DOS The Apple He family works with DOS 3.3. Its built-in disk drive hardware and firmware can also access DOS 3.2 disks by using the BASICS disk. DOS support is provided for the sake of Apple II—series compatibility; neither version of DOS takes full advantage of all the features of the Apple He family. Pascal Operating System Versions 1.2 and later of the Pascal Operating System use the 80/40 switch and the interrupt features of the Apple He family, while remaining compatible with the other Apple II-series computers. Note that the Apple He Plus does not have an 80/40 switch. While the Apple He family works with Pascal 1.1, this version of the Pascal Operating System does not use the 80/40 switch or handle interrupts. The Apple He family does not work with Pascal 1.0, because the I/O firmware entry points of that version of the operating system are rigidly defined (rather than being accessed via a table), and the Apple He family operating firmware does not correspond to these entry points. 452 Apple He Technical Reference Languages This section discusses using Apple programming languages with the Apple lie family. Applesoft BASIC The programming examples in this manual are almost entirely in assembly language, and so most addresses and values are given in hexadecimal notation. Use a PEEK in BASIC (instead of LDA in assembly language) to read a location, and a POKE (instead of STA) to write to a location. The values used by Applesoft must be in decimal, so you will have to convert hexadecimal values given in this manual to decimal. (Several tables in this manual include decimal equivalents to make the job easier for you.) If you read a hardware address from a BASIC program, you get a value between 0 and 255. Bit 7 has a value of 128, so if a soft switch is on, its value will be equal to or greater than 128; if the switch is off, the value will be less than 128. Integer BASIC You will have to run a version of DOS in your Apple He family computer to use Integer BASIC. ProDOS does not support Integer BASIC. Pascal language The Pascal language runs on the Apple lie family under versions 1.1 or later of the Pascal Operating System. However, for best performance, use Pascal versions 1.2 or later. APPENDIX C Operating Systems and Languages 453 Fortran Fortran runs under version 1.1 of the Pascal Operating System, which does not detect or use certain Apple He family features, such as the 80/40 switch or auxiliary memory. Therefore, Fortran does not take advantage of these features either. Logo n Apple Logo II works under ProDOS on Apple II-series machines with at least 128 KB of memory. Logo II is a version of the Logo language originally developed from the LISP (I/St Processing) language at MIT as a language to be used for learning. Logo II takes advantage of Apple II graphics and retains much of the power and flavor of LISP without LISP's somewhat cryptic syntax. 454 Apple He Technical Reference Appendix D Apple H-Family Differences This appendix compares the Apple He to the Apple lie Plus, Apple He, Apple II Plus, and Apple II. It does not contain an exhaustive list of differences, but it does mention those differences most likely to affect the accuracy of programs, displays, and instructions created for end users of two or more Apple II-series models. The Apple IIGS computer differs in many important ways from all other Apple II computers. The Apple IIGS is not discussed in this appendix; see the Technical Introduction to the Apple IIGS for a summary of the features of the Apple IIGS computer. • 455 Overview The differences between the computers in the Apple II series can be expressed as equations: this computer equals that one plus or minus certain features. The following equations compare each model of Apple II series with its predecessor in terms of functional equivalence, not literal equality. For example, Apple n Plus - Apple U - Integer BASIC firmware does not mean that Integer BASIC firmware can be removed from the Apple 11—just that the one machine functions as if it were the other without such firmware. Apple II Plus Apple II Autostart ROM Applesoft firmware 48 KB RAM standard old Monitor ROM Integer BASIC firmware Apple He Apple II Plus Apple Language Card (with 16 KB of RAM) 80-column (enhanced) video firmware built-in diagnostics full ASCII keyboard internal power light FCC approval improved back panel 9-pin back-panel game connector auxiliary slot (with possibility of 80-column text card and extra 64 KB RAM) slotO interrupt support in firmware (enhanced Apple He) mini-assembler in firmware (enhanced Apple lie) 18key numeric keypad (extended keyboard Apple lie) 456 Apple He Technical Reference Apple lie = Apple lie + extended 80-column text card + 80/40 switch + keyboard switch + disk-use light + disk controller port + built-in 5.25-inch disk drive + mouse port + serial printer port + serial communication port + built-in port firmware + video expansion connector + external power transformer removable cover - slots 1 to 7 auxiliary slot internal power light cassette I/O connectors internal game I/O connector auxiliary video pin Monitor cassette support + mini-assembler in firmware (UniDisk 3.5 and later versions) + SmartPort in firmware (UniDisk 3.5 and later versions) + memory expansion card support (memory expansion version) Apple lie Plus = Apple He + 4 MHz 65C02 microprocessor + CGGA and cache RAM + SmartPort in firmware + mini-assembler in firmware + memory expansion card support + connector for internal modem + Apple Standard Keyboard layout + all-internal power supply + mini-DIN connectors for serial ports + support for security kit + firmware driver for Apple 3.5 disk drives + volume control on keyboard + built-in 3.5-inch disk drive with eject button built-in 5.25-inch disk drive 1 MHz 65C02 microprocessor - 80/40 switch volume control knob on side of case external audio jack APPENDIX D Apple II-Family Differences 457 ^ Type of processor The processor in the Apple II and II Plus is the 6502. The original Apple He uses a 6502A. The Apple lie family and later versions of the Apple He all use the 65C02; a redesigned CMOS 6502 with 27 new instructions, new addressing modes, and, for some instructions, a differing execution scheme and machine cycle counts (see Appendix A). The Apple He Plus uses a faster (4 MHz) version of the 65C02. A program will run on earlier Apple II machines only if it does not contain instructions unique to the 65C02 or depend on the timing of any of those instructions whose cycle times differ between the two processors. Your program is guranteed not to run on all versions of the Apple II if it uses any firmware entry points other than those in Appendix F. Machine identification Your Apple II program can tell which member of the Apple II family it is running on by checking the values in four locations of ROM (the identification bytes). Table D-l lists the machines and their identification bytes. • Table D-l Apple II-family identification bytes Location Machine $FBB3 SFB1E $FBC0 SFBBF Apple II $38 $60 $2F Apple II Plus $EA $AD $EA $EA Apple III (emulation mode) $EA $8A Apple He (original) $06 $EA $C1 Apple He (enhanced) $06 $E0 $00 Apple He (original) $06 $00 $FF Apple lie (UniDisk 3.5) $06 $00 $00 Apple He (memory expansion) $06 $00 $03 Apple He (memory expansion, revised ROM) $06 $00 m Apple He Plus $06 $00 $05 458 Apple lie Technical Reference Any future Apple II-series computer or ROM release will have different values in these locations. Machine identification routines are available from Apple Developer Technical Support. The MachID byte for ProDOS ($BF98 on the global page) has bit 3 set to 0 if the computer is an Apple II, II Plus, He, or III, and to 1 if the computer is not one of these machines. In an Apple lie family member, bits 7 and 6 are also set to binary 10. Bits 7 and 6 set to binary 10 indicate that a computer is Apple He and He compatible, regardless of the value of bit 3- Memory structure This section compares the memory organization of the Apple He and the Apple lie Plus with that of the Apple II, II Plus, and lie. These machines differ in RAM space, ROM space, slot or port address space, and hardware page use. Amount and address ranges of RAM The Apple II could have as little as 4 KB of RAM at the time of purchase, and could be upgraded to as much as 48 KB of RAM. The Apple II Plus has 48 KB of RAM ($0000 through $BFFF) as a standard feature. With the addition of an Apple Language Card, a 48 KB Apple II or II Plus could be expanded to have 64 KB of RAM. The Apple He has a full 64 KB of RAM. The top 12K addresses overlap with the ROM addresses $D000 through SFFFF. There is an additional bank-switched area of 4 KB from SD000 through $DFFF. This arrangement is equivalent to an Apple II Plus with an Apple Language Card installed. A program selects between the RAM and ROM address spaces and between the $D000 address spaces by changing soft switches located in memory. With an Apple He Extended 80-Column Text Card installed in its auxiliary slot, an Apple He has an additional 64 KB of RAM available, although no more than half of the 128 KB of RAM space is available at any given time. Soft switches located in memory control these address space selections. The Extended 80-Column Text Card is included with each enhanced Apple He, and comes permanently installed in the extended keyboard Apple He. APPENDIX D Apple II-Family Differences 459 The RAM in the Apple lie and Apple He Plus is equivalent to the RAM in an Apple He with an Extended 80- Column Text Card. The optional memory expansion card can add as much as 1 MB of RAM to the memory expansion Apple He or Apple lie Plus in 256 KB steps. Amount and address ranges of ROM The Apple II has 8 KB of ROM (SE000 through SFFFF), and the Apple II Plus has 12 KB of ROM (SDOOO through SFFFF). Users can plug their own ROMs into the sockets provided. The on-board (as opposed to slot) ROM address range is from $D00O through SFFFF. The Apple He has 16 KB of ROM, of which it uses 15.75 KB (addresses $C100 through $FFFF; page SCO addresses are for I/O hardware). ROM addresses SC300 through SC3FF (normally assigned to the ROM in a card in slot 3) and $C800 through $CFFF contain 80-column video firmware; ROM addresses SC100 through $C2FFand SC400 through $C7FF (normally assigned to the ROM on cards in slots 1, 2,4,5,6, and 7) contain built-in self-test routines. A soft switch in RAM controls whether the video firmware or slot 3 card ROM is active. Invoking the self-tests with Option-Control-Reset causes the self-test firmware to take over the slot ROM address spaces. The Apple He-family ROM also uses the 15.75 KB from $C100 through $FFFF, and its enhanced video firmware has the same entry point addresses as on the Apple He. However, there are only rudimentary built-in self-tests, and these do not preempt any port firmware space. The UniDisk 3.5 and memory expansion versions of the Apple He and the Apple He Plus have twice the ROM (32 KB) of the original Apple lie. The extra ROM contains support for the SmartPort, a mini-assembler, Step and Trace functions in the Monitor firmware, expanded self-test routines, improved interrupt support, and, in the Apple lie Plus, a disk driver for Apple 3.5 disks. Whereas most of the second 16 KB of ROM in the Apple Be is empty, in the Apple he Plus, all of the available ROM is used. In the Apple lie and Apple He Plus, main ROM addresses SC100 through $CFFF contain I/O and interrupt firmware, addresses $D000 through $F7FF contain the Applesoft BASIC interpreter, and addresses $F800 through $FFFF contain the Monitor. 460 Apple He Technical Reference Peripheral-card memory spaces Each port in an Apple He-family computer has up to 16 peripheral-card I/O space locations in main memory on the hardware page (beginning at location $C0n0 + $80 for slot or port n), allocated in the standard Apple II-series way (that is, beginning at location SCOnO + S80 for each slot n). 'lhe peripheral-card ROM space (page $Cn for slot n in the Apple II, II Plus, and He) contains the starting and entry-point addresses for port n, but port routines are not limited to their allocated SCn pages. The 2 KB expansion ROM space from SC800 to $CFFF in the Apple Be family is used by the enhanced video firmware and miscellaneous I/O and memory-transfer routines. The 128 bytes of peripheral-card RAM space or scratch-pad RAM (64 screen holes in main memory and their equivalent addresses in auxiliary memory) arc reserved for use by the built-in firmware. It is extremely important for the correct operation of Apple Ilc-family firmware that these locations not be altered by software except for the specific purposes described in Chapters 3,7, and 9. Hardware addresses The hardware page (the addresses from $C000 through SCOFF) controls memory selection and input/output hardware characteristics. All input and output (except video output) Lakes place at one or more hardware page addresses. For the sake of simplicity, this section presents only a general comparison between the Apple lie family on the one hand, and the Apple II, II Plus, and He on the other, with respect to hardware page use. However, for many characteristics, the Apple He and lie work one way, while the Apple li and II Plus work another. $C000-$C00F On all Apple II-series computers, reading any one of these addresses reads the keyboard data and strobe. On the Apple Be and lie, writing to each of these addresses turns memory and display switches on and off. Writing to addresses SC006, $0007, $C00A, and $C00B performs ROM selection on the Apple lie. Writing to these four addresses is reserved in the Apple He family. For reading the keyboard, use $C000; reserve SC001 through $C00F. APPENDIX D Apple II-Family Differences 461 $C010-$C01F On all Apple II-series computers, writing to any one of these addresses clears the keyboard strobe. On the Apple He and He, reading each of these addresses checks the status of a memory or display switch, or the any- key-down flag. For clearing the keyboard strobe, use $0310; reserve $C011 through SC01 P. Reading SC015 checks the SLOTCXROM switch on the Apple lie, but it resets the X-movement interrupt (XInt) in the Apple lie family. Similarly, reading $C017 checks the SLOTC3ROM switch on the Apple lie, but it resets the Y-movement interrupt (YInt) in the Apple lie family. Reading $C019 checks the current state of vertical blanking (VBL) on the Apple He, but it reads and then resets the vertical blanking interrupt flag in the Apple lie family. $C020-$C02F On the Apple II, II Plus, and lie, reading any address $C02x toggles the cassette output signal. On the original Apple He, both reading from and writing to these locations are reserved. Apple lie versions with 32 KB of ROM—including the Apple He Plus—use $C028 to switch in or out the extra 16 KB of ROM. $C030-$C03F On all Apple II-series computers, reading an address of the form $C03x toggles the speaker. For full Apple II- series compatibility, toggle the speaker using $0030, and reserve $0331 through $C03F. For the Apple Be family, writing to $C031 through $C03F is explicitly reserved. $C040-$C04F On the Apple II, II Plus, and He, reading any address of the form $C04x triggers the utility strobe. The Apple He family has no utility strobe. For the Apple lie family, addresses $C044 through $C047 are explicitly reserved, and reading or writing any address from $C048 through $C04F resets both the X and Y mouse interrupts (XInt and YInt). 462 Apple lie Technical Reference $C05O-$C05F Addresses $C050 through $C057 work the same on the Apple lie family as on the Apple He: they turn the Text, Mixed, Page2, and HiRes switches on and off. On the Apple He, addresses $0358 through SC05F turn the annunciator outputs on and off. On an Apple He with a revision B main logic board or later, an Apple He Extended 80-Column Text Card, and a jumper installed on the card, reading locations $C05E and $C05F set and clear Double Hi-Res display mode. In the Apple He family, if the IOUDis switch is on, both reading from and writing to addresses SC058 through SC05D are reserved, and addresses $C05E and SC05F set and clear the Double Hi-Res display (as on the Apple He equipped as described in the preceding paragraph). If the IOUDis switch is off, then addresses $C058 through SC05F control various characteristics of mouse and vertical blanking interrupts (listed in Table 9-2). $C06O-$C06F For the Apple He family, writing to any address of the form $C06x is reserved, and reading addresses $C068 through $C06F is reserved. Reading addresses $C06l and $C062 is the same as on the Apple lie (switch inputs, Command, and Option). Reading addresses $C064 and SC065 is the same as on all other Apple II-series computers (analog inputs 0 and 1). For the Apple He family, address $C063 bit 7 is 1 if the mouse switch is not pressed, and 0 if it is pressed, so that software looking for the Shift-key mod (used on Apple II, II Plus, and He with some text cards) will find it and display lowercase correctly. If by chance the mouse button is pressed when the software checks location SC063, it will appear that the Shift-key mod is not present. On the Apple He, address $C060 is used for reading the state of the 80/40 switch; on the Apple II, II Plus, and lie, this address is for reading cassette input. On the Apple He Plus, this address is reserved. The Apple lie family has two, rather than four, analog (paddle) inputs. Addresses $C066 and $C067 are used for reading the mouse X and Y direction bits. APPENDIX D Apple II-Family Differences 463 $C070-$C07F On the Apple II, II Plus, and He, reading from or writing to any address of the form $C07n triggers the paddle timers (analog input). In the Apple lie family, only address SC070 is to be used for that one function. Addresses SC071 through SC07D are explicitly reserved. The results of reading from or writing to addresses SC07E and SC07F are described in Table 6-9. $C080-$C08F On the Apple He and He, accessing addresses in this range selects different combinations of bank-switched memory banks. However, addresses $C084 through SC087 duplicate the functions of the four addresses preceding them, and addresses $C08C through SC08F do also. These eight addresses are explicitly reserved on the Apple He and Apple He Plus. $C090-$C0FF On the Apple II, II Plus, and Be, each group of 16 addresses of the form SC080 + $n0 is allocated to an interface card (if present) in slot n. For the Apple lie family, addresses corresponding to slots 1,2, 3,4, and 6 are allocated to a serial interface card, communication interface card, 80-column text card, mouse interface card, and disk controller card, respectively. All other addresses in this range are reserved. System Monitor The older models of the Apple II and Apple II Plus included a different version of the System Monitor from the one built into more recent models (and the Apple lie and lie). The older version, called the Monitor ROM, had the same standard I/O subroutines as the newer Autostart ROM, but a few of their features were different; for example, there were no arrow keys for vertical cursor motion. 464 Apple He Technical Reference When you start an Apple Be family member with a DOS or BASICS disk and it loads Integer BASIC into the bank-switched area in RAM, it loads the old Monitor along with it. When you type INT from Applesoft to activate Integer BASIC, you also activate this copy of the old Monitor, which remains active until you either type FP to switch back to Applesoft, which uses the new Monitor in ROM, or activate the 80-column firmware. I/O in general Apple He-family I/O is different from I/O on the Apple II, II Plus, and Be in three important respects: the possibility of direct memory access (DMA) transfers, the presence or absence of slots, and the presence or absence of built-in interrupt handling. DMA transfers The Apple II, II Plus, and He allow DMA transfers, because both the address and the data bus are available at the slots. No true DMA transfer is possible with the Apple He family because neither bus is available at any of the back panel connectors. Slots versus ports The Apple II and II Plus have eight identical slots; the Apple He has seven identical slots plus a 60-pin auxiliary slot for video, add-on memory, and test cards. The Apple Be family has no slots; instead, each computer has back panel connectors and built-in hardware and firmware that are functional equivalents of slots with cards in them. The back panel connectors are called ports for the Apple lie family. APPENDLX D Apple II-Family Differences 465 Interrupts The original Apple He was the first computer in the Apple II series to have built-in interrupt-handling capabilities. The enhanced Apple He has very similar interrupt-handling capability included. The keyboard Both keyboard layout and character sets vary in the Apple II-series computers. The major keyboard difference in the Apple II series is that the Apple he, Apple lie, and Apple lie Plus have full ASCII keyboards, while the Apple II and II Plus do not. The extended keyboard version of the Apple He includes an 18key numeric keypad. Keys, switches, and lights The Apple II and Apple II Plus computers have identical keyboards with 52 keys (including the Reset switch). The Apple Be and Apple lie keyboards have the same 62-key full ASCII keyboard layout, with new and repositioned keys and characters as compared to the Apple II and Apple II Plus. Whereas the Apple II and Apple II Plus have a Repeat key, theApple He andApple lie have an auto-repeat feature built into each character key. The Apple Be Plus has the same keyboard layout as the Apple Standard Keyboard used by the Apple IIGS and some Macintosh computers; the Apple lie Plus keyboard does not include a numeric keypad, however. Some Apple II and Apple II Plus machines have a slide switch inside the case, under the keyboard edge of the cover, for selecting whether or not Reset works without Control. On the Apple He and Apple lie family, there is no choice: Control-Reset works, and Reset alone does not. The Apple lie andApple lie have up arrow and down arrow keys, an Open Apple key (now called Command), and a Solid Apple key (now called Option); the Apple II and Apple II Plus do not have these four keys. On the extended keyboard Apple He and on the Apple He Plus, the Solid Apple key is relabeled as the Option key. The captions on several other keys—Esc, Tab, Control, Shift, Caps Lock, Delete, Return, and Reset—can vary: on the Apple II and Apple II Plus some are abbreviated or missing; on the Apple He family all keycaps are lowercase italic; on international models, some captions are replaced by symbols (see Appendix E). 466 Apple He Technical Reference The Apple lie has two switches that the other models do not have. One switch is for changing between 40- column and 80-column display, the other is for selecting keyboard layout (Sholes versus Dvorak on USA models), or both keyboard layout and character set (on international models). The Apple Be Plus does not have an 80/40 switch; in its place is the speaker volume control. The position of the power-on light differs on the Apple II and Apple II Plus, Apple He, and Apple lie family computers. The Apple He and Apple Be Plus have a disk-use light as well. Character sets The Apple II and II Plus keyboard character sets are the same. They are described in the Apple II Reference Manual. The Apple He and Apple He family keyboard character sets are the same: full ASCII. The various keyboard layouts and key assignments for Apple He family computers are shown in Chapter 1 and Appendix E of this manual. To change between the two available keyboard layouts requires modification to the main logic board on the Apple He, but only toggling of the keyboard switch on the Apple He family. Apple Computer, Inc., manufactures fully localized models (with regard to power supply and character sets) of both the Apple Be and the Apple He. However, there are minor variations in keyboard layout, even among early and late production models of the same machine. For further details, refer to Appendix E of this manual. The speaker lhe Apple Be has two speaker features that the three previous models do not have: a two-channel, but monaural, audio output jack for headphones, which disconnects the internal speaker when something is plugged into it, and a volume control. The Apple lie Plus has a volume control but no audio output jack. APPENDIX D Apple II-Family Differences 467 The video display This section discusses the general differences between Apple Be family video display capabilities and those of the other computers in the series. Character sets The Apple II and II Plus display only uppercase characters, but they display them in three ways: normal, inverse, and flashing. The Apple lie family and Apple He can display uppercase characters in all three ways, and they can display lowercase characters in the normal way. This combination is called the primary character set. The Apple lie family and Apple He have another character set, called the alternate character set, that displays a full set of normal and inverse uppercase and lowercase characters, but can't display flashing characters. The primary and alternate character sets are described in Chapter 6. You can switch character sets at any time by means of the AltChar soft switch, also described in Chapter 6. Flashing display must not be used with the enhanced video firmware active. Use it in 40-column mode with the enhanced video firmware turned off; otherwise, strange displays may result, such as MouseText characters appearing in place of uppercase letters. To be sure of compatibility with some software, you have to switch the Apple lie family member's keyboard to uppercase by pressing Caps Lock. MouseText The Apple lie family computers and the enhanced and extended keyboard Apple He computers include a set of graphic text characters, called MouseText characters, that replace some of the inverse uppercase characters in the alternate character set of the original Apple He. The MouseText characters are shown in Figure 6-2, in Chapter 6. 468 Apple lie Technical Reference Vertical blanking A signal called vertical blanking indicates when a display device should stop projecting dots until the display mechanism returns from the bottom of the screen to the top to make another pass. During this interval, a program can make changes to display memory pages, and thus provide a smooth, flicker-free transition to a new display. On the Apple lie, vertical blanking (VBL) is a signal whose level must be polled. (VBL is not available to software on the Apple II or Apple II Plus.) In the Apple lie family.there is also a vertical blanking interrupt (VBlInt) that is generated by the IOU on the trailing edge of the active-low VBL signal. Programs intended to run on all Apple II-series computers must take this difference into account. Display modes All models have 40-column text mode, Lo-Res graphics mode, Hi-Res graphics mode, and mixed graphics and text modes. The Apple He (revision B main logic board) with an Apple He Extended 80-Column Text Card, and the Apple He family have Double I li-Rcs graphics mode also. Disk I/O The Apple II, Apple II Plus, and Apple He can support up to six disk drives (although four is the recommended maximum) attached to controller cards plugged into slots 6, 5, and 4. The original Apple He supports two 5.25-inch disk drives: its built-in drive and one external disk drive. The UniDisk 3.5 Apple lie supports up to three disk drives: its built-in 5.25-inch disk drive, one external 5.25-inch disk drive, and one external 3.5-inch disk drive. The memory expansion Apple He supports up to four disk drives, which can be any combination of its built-in 5.25-inch disk drive, one external 5.25-inch disk drive, and up to three external 3.5-inch disk drives. The Apple lie Plus supports up to four disk drives, which can be any combination of its built-in 3.5-inch drive, one external Apple 3.5 drive, up to three external UniDisk 3.5 drives, and up to two 5.25-inch disk drives. APPENDLX D Apple II-Family Differences 469 Serial I/O The Apple He-family serial ports (ports I and 2) are similar to Super Serial Cards installed in slots 1 and 2 of an Apple He. The serial port commands are a slightly modified subset of Super Serial Card commands. This subset includes all the commands supported by the earlier Apple Serial Interface Card and Communication Card. Serial ports versus serial cards There are several important differences between Apple lie family serial ports and other Apple II-series computers with serial cards installed in them. Apple Ilc-family serial ports have no switches. Instead, initial values are moved from firmware locations into auxiliary memory when the power is turned on. Changes made to these values in auxiliary memory remain in effect until \he power Is turned off. Pressing Command-Control-Reset does not change them (because it does not affect auxiliary memory, only main memory). When the port itself is turned on (with an IN or PR command), the initial values in auxiliary memory are placed in the main memory screen holes assigned to the port. These characteristics can be changed by the port commands. The changed characteristics remain in effect until the port is turned off and then on again (with PR and IN commands). The command syntax for the Apple Ilc-family ports also differs from the syntax for serial cards. A separate command character, Control-A or Control-I, must precede each individual port command, whereas several commands to a serial card can be strung together between the command character and a carriage return character. The letters used for some of the commands have been changed from those used with the Super Serial Card (such as S instead of B for sending a Break command). To simplify command interpretation, each serial port command letter is unique. Changing the command character from Control-A to Control-I, or vice versa, makes the Super Serial Card change from communication mode to printer mode and back; this is not the case with Apple Ilc-family serial ports. With the Apple He family, use the system utilities to change modes. 470 Apple lie Technical Reference Super Serial Card commands support some functions that Apple Ilc-family serial port commands don't support: translating incoming characters, such as changing lowercase to uppercase (for the benefit of the Apple II or II Plus); delaying after sending carriage return, line feed, or form feed, and so on. Following a Control-I nnnN command, the Apple He automatically generates a carriage return after nnn characters; with the Super Serial Card, you need to turn this feature on with Control-I C. A complete description of the Apple Ilc-family serial port command set is given in Chapter 7. Serial I/O buffers The communication port firmware uses auxiliary memory page $08 as an input and output buffer. By doing so, the firmware can keep up with higher baud rates. It can also hide data from the Monitor, Applesoft, and other system software. Programs written for the Apple lie or lie can, of course, store information in auxiliary memory page $08. However, such information is destroyed when the communication port is activated. Mouse and hand controls The DB-9 connector on the back panel of the Apple Ilc-family computers is used for both the mouse and hand controls. On the Apple He, the DB-9 connector supports hand controls only; the mouse must use the connector on the interface card. APPENDIX D Apple II-Family Differences 471 Mouse input The Apple lie family provides built-in firmware support for a mouse connected to the DB-9 mouse and hand control connector. Apple Ilc-family mouse support includes mouse movement and button interrupts (and vertical blanking interrupts for synchronization with the display); Apple He mouse support relies on polling VBL instead of vertical blanking interrupts. As a result of how interrupts are handled on the two machines, the mouse firmware routine calls function somewhat differently for the Apple lie family and Apple He. However, using the calls in the manner described in Chapter 9 and in this section ensures mouse support compatibility between the two machines. The ratio of mouse movement to cursor movement on the Apple lie family is different from that on the Apple lie. The Apple lie mouse card has a microprocessor on it that regularly polls the mouse to get status and position information. This data is then kept on the card and is available whenever the program requests it through the ReadMouse routine. If the mouse is in transparent mode, your program can read this information at any time. You can use the SerMouse routine to control the conditions upon which the mouse card issues interrupts: any combination of motion in the X direction, motion in the Y direction, and mouse-button activity. When the mouse card issues an interrupt, the CPU passes control to the interrupt handler, which reads the information from where the card processor saved it and puts it in the screen holes. A program running on an Apple lie computer with a mouse card is interrupted only under the conditions you have specified, and the data in the screen holes is changed only when the user interrupt handler or your program's polling routine calls ReadMouse. Enabling and inhibiting mouse interrupts does not affect the updating of mouse information by the mouse card's microprocessor. The Apple He mouse does not have a card microprocessor and so the mouse information is collected by the CPU when it receives a mouse interrupt. When the interrupt handler determines that the interrupt was caused by the mouse, the firmware reads the mouse status and updates the screen holes. As for the Apple He, whether the interrupt is passed on to your program depends on which interrupts have been enabled using the SetMouse routine. However, because the mouse interrupts the computer's microprocessor, execution of your program is delayed when the mouse is used whether the interrupts are passed on to your program or not. The system interrupt handler not only reads the mouse status from the mouse hardware, but also updates the screen holes with the mouse location, because there is no mouse card on which to temporarily store this data. These delays affect the timing of your program. If your program disables interrupts to preserve program timing, the mouse can never interrupt the processor and so the X and Y values in the screen holes are never updated. In that case, a call to ReadMouse would indicate that there has been no mouse movement. 472 Apple He Technical Reference To minimize the effect on your program of the servicing of mouse interrupts by firmware, the Apple lie does not generate a mouse interrupt until the mouse has moved twice as far as required by a mouse card in the Apple He. To cause mouse behavior on a member of the Apple Ilc-family to appear to be the same as that of an Apple He mouse, multiply the Apple lie X and Y values by 2 and set the clamping values to 1/2 those used for the Apple He. With Lhe exception of having to double the amount of mouse movement for Apple Ilc-family computers, your assembly-language program can ignore which machine it is running on by obeying the precautions in the following list. If you are using BASIC or Pascal, these conditions are taken care of for you. • Disable interrupts with an SEI instruction when calling any mouse routine. • Do not disable interrupts except when absolutely necessary, and be sure to reenable them as soon as possible. • Do not reenable interrupts after executing the ReadMouse routine until you have read the X and Y mouse motion data from the screen holes.. • Disable interrupts before using the PosMouse or ClampMouse routines to place mouse position information in the screen holes. • Before executing any mouse routine other than ServeMouse, set the X register to SCn and set the Y register to $n0, where n is the slot number for the mouse card in the Apple He, 4 for the Original and UniDisk 3.5 Apple He computers, and 7 for the memory expansion Apple He and the Apple He Plus • If your program must disable interrupts for some reason other than to execute a mouse routine, the first call to the ReadMouse routine after you reenable interrupts may give incorrect values. Subsequent calls to ReadMouse will return correct values until the next time you disable and reenable interrupts. For example, if your program is reading X values from the mouse while the user is moving it in a direction that would increase values, and interrupts are disabled and reenabled between ReadMouse calls, the X values might change as follows: 6,7,8, 9,8,9,10. In practice this slight error in mouse position would probably not be noticed by the user. If you must keep this error from occurring, then do not leave interupts disabled for more then 40 microseconds, or be sure that at least one mouse interrupt has taken place since interrupts were reenabled before calling the ReadMouse routine. Disabling interrupts for mouse calls does not create this problem. APPENDIX D Apple II-Family Differences 473 Hand control input and output The Apple II, Apple II Plus, and Apple He have a 16-pin connector (labeled GAME I/O) inside the case that supports three switch inputs, four analog (paddle) inputs, and four annunciator outputs. The Apple He and Apple He family have a DB-9 back panel connector that supports the three switch inputs and two paddle inputs. The Apple lie family does not support the four annunciator outputs. The characteristic response curve for Apple He-family hand controls differs for the from that of the Apple II, II Plus, and He. Compare Figure D-l with Figure 11-45. The response curve is different so the hardware can support identifiable mouse and hand control signals using the same circuits. The paddle-timing circuit in the Apple II Plus is slightly different from the one in the Apple lie and Apple lie family. In the Apple He and Apple He the 100-ohm fixed resistor is between the NE556 discharge lead and the capacitor; the variable resistor in the paddle is connected directly to the capacitor. In the Apple II Plus, the capacitor is connected directly to the discharge lead, and the fixed resistor is in series with the paddle resistor. • Figure D-l Apple II, Apple II Plus, and Apple lie hand control signals Input Current (mA) Undefined 10 9 8 - , i • -. 1 ii 7 - • . . N . ' . * * - * . • . • » * ; * » j , - 5 « * i ' * • . »'"V: ? ..;Vr-^ f f ;"-v-;rr 0 ''• i r'' " •. ' j '" 5 . V.••••'. ' .••*>.• •'-•--. .'•-••. •*. '; ,.t 4 " -I' I 3 ftA'.1*.'r.> 2 1 —1—p 1 0.8 1 2.4 S Input Voltage (volts) 474 Apple Uc Technical Reference Cassette I/O The Apple II, II Plus, and He all have cassette input and output jacks, memory locations, and Monitor support. The Apple lie family does not. Hardware Besides the different microprocessors used in various models in the Apple II series, there are important differences in power specifications and custom chips. Power The power supplies for the Apple II, II Plus, and He are essentially the same. Both the external power transformer and internal voltage converter for the Apple lie have smaller capacity for current and heat dissipation. Therefore, it is important to observe the load limits specified in each of the reference manuals. The Apple He Plus computer's power supply is completely internal but otherwise has the same specifications as that of the Apple He. APPENDIX D Apple II-Family Differences 475 Custom chips The Apple He custom chips (memory management unit and input/output unit) replaced dozens of Apple II Plus chips, and added dozens of new functions. The Apple He family also has custom MMU and IOU chips, but they are different ICs from those used in the Apple lie. The Apple lie has four other custom ICs: a general logic unit (GLU), a timing generator (TMG), and a disk controller unit (IWM). The Apple lie has two hybrid circuits (AUD and VID) for audio and video amplification. In the Apple He Plus, the audio hybrid circuit is replaced by equivalent discrete components on the circuit board. The Apple lie Plus has two additional custom chips: the multidrive interface glue (MIG) chip, which provides a RAM buffer and hardware interface for 3.5-inch disk drives; and the cache glue gate array (CGGA), which controls a RAM cache and provides a 4 MHz clock for the 65C02. 476 Apple He Technical Reference Appendix E USA and International Models This appendix shows the keyboard layouts and gives the key codes for USA and international models. Some of the keyboard information given in Chapter 5 for the two USA keyboard layouts for the Apple lie computer is repeated here for easy comparison with the other layouts available. There are no international versions of the Apple He Plus computer. • r 477 Keyboard layouts and codes Each of the following subsections has a keyboard illustration and a table of the codes that result from the possible keystrokes. Note, however, that Table E-l is the basic table of keystrokes and their codes. For simplicity, subsequent tables (up to Table E-7) list only the keystrokes and codes that differ from those in Table E-l. For example, pressing the A key produces a (hexadecimal 6l); pressing Shift-A produces uppercase A (hexadecimal 41); pressing Control-A or Control-Shift-A produces SOH(\he ASCII Start Of Header control character, hexadecimal 01). You can tell that this key has the same effect on all keyboards because nothing appears in Tables E-2 through E-7 for that key. A quick way to find out which characters in the ASCII set change on international keyboards is to check Table E-9. In fact, only a few of them change. The pairing of characters on keys varies more. • Note: On all but the French and Italian keyboards, Caps Lock affects only keys that can produce both lowercase letters (with or without an accent) and their uppercase equivalents. With these keys, Caps Lock down is equivalent to holding down Shift, resulting in uppercase instead of lowercase. If a key produces only a lowercase version of an accented letter, then Caps Lock does not affect it. On the French and Italian keyboards, Caps Lock shifts all the keys. Furthermore, on the French keyboard, when Caps Lock is down the Shift key undoes the shifting. The shapes and arrangement of keys in Figures E-l and E-2 follow the ANSI (American National Standards Institute) standard, which is used mainly in North and South America. The shapes and arrangement of keys in Figure E-3 follow the ISO (International Standards Organization) standard used in Europe and elsewhere. The only differences between the ANSI and ISO versions of the USA keyboard are • the shapes of three keys: the left Shift key, Caps Lock, and Return • the position of two keys (I and ~) (compare Figures E-l and E-3) • the arrow symbols on Tab, Caps Lock, Return, and the two Shift keys (as shown in Figure E-3) 478 Apple lie Technical Reference USA standard (QWERTY) keyboard Figure E-l shows the standard (Sholes or QWERTY) keyboard as it is laid out for USA models of the Apple lie with the keyboard switch up. Table E-l lists the ASCII codes resulting from all single and combination keystrokes on this keyboard. • Figure E-l USA standard (QWERTY or Sholes) keyboard, keyboard switch up reset IJBOfiO IIkeyboard I disk use I no, ' -1 I St s % " i * ( ; _ esc 1 2 3 4 5 6 7 8 9 0 - = delete [ } 1 lab 0 W f R r Y U 1 0 P [ ] \ control A s D F G H J K L return < > sfuft Z X C V B N M 1 shift csps -j. -a. • lack \ L . . . . , , _^ . . , , Table E-l Keys and ASCII codes (hexadecimal) Key Key alone + Control + Shift + Both Code Char Code Char Code Char Code Char Delete 7F DEL 7F DEL 7F DEL 7F DEL Left Arrow 08 BS 08 BS GS BS 06 BS Tab 09 HT 09 IIT 09 HT 09 HT Down Arrow OA LF OA LF 0A LF 0A LF Up Arrow OB VT 0D VT 0B VT 0B VT Return OD CR 0D CR 0D CR 0D CR Right Arrow 15 NAK 15 NAK 15 NAK 15 NAK Esc IB ESC IB ESC IB ESC IB ESC Space 20 SP 20 SP 20 SP 20 SP • ii i N 27 27 l 22 II 21 APPENDIX. E USA and International Models 479 Table E-l Keys and ASCII codes (hexadecimal) (continued) Key Key alone + Control + Shift + Both Code Char Code Char Code Char Code Char ,< 2C i 2C , 3C < 3C < -_ 2D - IF US 5F IF US .> ZE 2E 3E > 3E > /? 2F / 2F / 3F ? 3F ? 0) 30 0 30 0 29 ) 29 ) 1! 31 1 31 1 21 I 21 I 2® 32 2 00 NUL 40 ® 00 NUL 3# 33 3 33 3 23 f 23 # 4$ 31 4 54 4 24 $ 24 $ 5% 35 5 35 5 25 % 25 % 6A 36 6 IE RS 5E A IE RS 7& 37 7 37 7 26 & 26 & 8' 38 8 38 8 2A 1 2A * 9( 39 9 39 9 28 ( 28 ( i * 3B 3B 3A 3A =+ 3D = 3D = 2B + 2B + !( 5B 1 IB ESC 7B { IB ESC \l 5C \ IC FS 7C IC FS ]} 5D ] ID GS 7D ) ID GS i~ 60 1 60 I 7E - 7E - A 61 a 01 SOH 41 A 01 SOH B 62 b 02 STX 42 B 02 STX C 65 c 03 ETX 43 C 03 ETX D 64 d 01 EOT 44 D Oi EOT E 65 e 05 ENQ 45 E 05 ENQ F 66 f 06 ACK 46 F 06 ACK G 67 8 07 BEL 47 G 07 BEL H 68 h C8 BS 48 11 08 BS I 69 i 09 HT 49 I 09 HT J 6A j 0A LF 4A J OA LF K 6B k 0B VT 4B K 0B VT 1. 6C 1 OC FF 4C L OC FF M 6D m 0D CR 4D M 0D CR N 6E n 0E SO 4E N 0E SO 0 6F 0 OF SI 4F 0 OF SI P 70 P 10 DLE 50 P 10 DLE Q 71 q 11 DC1 51 Q 11 DC1 480 Apple lie Technical Reference Table E-l Keys and ASCII codes (hexadecimal) (continued) Key Key alone + Control + Shift + Both Code Char Code Char Code Char Code Char R 72 r 12 DC2 52 R 12 DC2 S 73 s 13 DC3 53 13 DC3 T 74 t 14 DC4 Si T 14 DC4 U 75 u 15 NAK 55 11 15 NAK V 76 v 16 SYN 56 V 16 SYN W 77 w 17 ETB 57 w 17 ETB X li X 18 CAN ss X 18 CAN Y 79 y 19 EM 59 Y 19 EM Z 7A z 1A SUB 5A Z 1A SUB USA simplified (Dvorak) keyboard Figure E-2 shows the Dvorak layout of the USA keyboard. This is the layout of keys that is in effect when the keyboard switch is in its down position. All keystrokes produce the same ASCII codes as those shown in Table E-l. • Figure E-2 USA simplified (or Dvorak) keyboard, keyboard switch down; shaded characters may be in different positions on some models. /reset / /jBOMO /jh keyboard I disk use I power 01 • — i > " " 1 @ S & ( ) n / / esc ! 2 3 4 5 6 7 8 9 0 I } delete U < > ? + i tab P Y F G C R L / \ — ccntml A 0 E U 1 D H T N S return sbilt Q J K X B M W V z shift caps locr. 0 « <-•• ••-> •i t APPENDIX E USA and International Models 481 ISO layout of USA keyboard Figure E-3 shows the layout of all ISO European keyboards (except the Italian keyboard) when the keyboard switch is up. All keystrokes produce the same ASCII codes as those shown in Table E-l. • Figure E-3 ISO version of USA standard keyboard, keyboard switch up j reset j JJ60/40 NM / n /© 1 9 S % " & * / ) _ + esc 1 2 3 4 5 8 7 8 9 0 ~ = delete ( } ^V 0 W E R T Y U 1 0 P I 1 <] tf contrnl A S D F G H J K L : • 1 < > ? O \ Z X C V B N M / o 0 d * <-•• •"•> i f British keyboard With the keyboard switch up, the British model of the Apple He keyboard layout is as shown in Figure E-3, and keystrokes produce the ASCII codes shown in Table E-l. With the keyboard switch down, the British model keyboard layout is as shown in Figure E-4. The change in ASCII code production (from that in Table E-l) is shown in Table E-2. The only changed character is the substitution of the British pound-sterling symbol (£) for the number symbol (#) on the shifted 3-key. 482 Apple He Technical Reference • Figure E-4 British keyboard, keyboard switch down reset jjmm [Jim /a /o • •• < ' ! @ £ S % " & * ( 1 _ esc 1 2 3 4 5 6 7 8 9 0 delete { } tab 0 W E R J Y U I 0 P i 1 return ft A S D F J \ control G H K L • ' 1 < > ? shiii \ Z X C V B N M . 1 M caps lock d m <••• •-> j, t Table E-2 British keyboard code differences from Table E-l Key Key alone Control Shift + Both Code Char Code Char Code Char Code Char 3i 33 3 33 3 23 i 23 £ Note: Codes are in hexadecimal. French keyboard With the keyboard switch up, the French model of the Apple He keyboard layout is as shown in Figure E-3, and keystrokes produce the ASCII codes shown in Table E-l. With the keyboard switch down, the French model keyboard layout is as shown in Figure E-5. The changes in ASCII code production (from that in Table E-l) are shown in Table E-3. Note that on the French keyboard, Caps Lock shifts to the upper characters on all keys. With Caps Lock on, Shift "unshifts" to the lower character on any key pressed with it. APPENDIX E USA and International Models 483 Figure E-5 French keyboard, keyboard switch down /reset / /jmm /jMH / B /© ! 2 3 4 5 6 7 8 9 0 " _ esc & g a < j § e < c a ) - /Mete -H A Z E R T Y li 1 0 P «J • % £ control 0 s 0 F G H J K I M u > '•' 1 + o < W X C V B N : : = O 0 d « «-• ~# i t Table E-3 French keyboard code differences from Table E-l Key Key alone + Control + Shift + Both Code Char Code Char Code Char Code Char &1 26 & 26 & 31 1 31 1 e2 7B i 7B 6 32 2 32 2 N "3 22 22 II 33 3 33 3 1 •4 27 27 • 34 4 34 4 C5 28 ( 28 ( 35 5 35 5 S6 5D 5 ID GS 36 6 ID GS e7 7D e 7D e 37 7 37 7 !8 21 i 21 i 38 8 38 8 99 5C C IC FS 39 9 IC FS :iO 40 a 00 NUL 30 0 00 NUL o )° 29 ) IB ESC 5B IB ESC A" 5E A IE RS 7E IE RS 484 Apple He Technical Reference Table E-3 French keyboard code differences from Table E-l (continued) Key Key alone + Control • Shift + Both Code Char Code Char Code Char Code Char 24 2A ) 2A • $* $ 24 $ u% 7C U 7C U 25 % 25 % v % "i 60 60 23 i 23 i, <> 3C < 3C < 3E > 3E > 7 2C i 2C i 3F J 3F 1 »* 3B 2E 2E 3B i i 1 * :/ 3A 3A 2F / 2F 1 Note-. Codes are in hexadecimal. Canadian keyboard With the keyboard switch up, the Canadian model of the Apple He keyboard layout is as shown in Figure E-l, and keystrokes produce Lhe ASCII codes shown in Table E-l. With the keyboard switch down, the Canadian model keyboard layout is as shown in Figure E-6. The changes in ASCII code production (from that in Table E-l) are shown in Table E-4. APPENDIX E USA and International Models 485 Figure E-6 Canadian keyboard, keyboard switch down reset [j80/40 /]:::: /H /© i '' ' ' •' 'i i + 6 * ' 9 ° #£ S % *§ 0 = dekne esc 7 8 9 1 2 3 4 5 6 f e tab Q W E R r Y U 1 0 P [a ] u \ " control A S 0 F G H J K L return < > •> c shift Z X C V B H M / e -'"ii caps lock d Table E-4 Canadian keyboard code differences from Table E-l Key Key alone + Control + Shift + Both Code Char Code Char Code Char Code Char 0 2° 32 2 00 NUL 5B 00 NUL 3£ 33 3 33 3 23 i 23 £ 6§ 36 6 RS IE 5D 5 RS IE ae 40 a 7F DEL 7D e 7F DEL DA 7C U 7C U 5E A 5E A N ? 60 *• ESC IB 3F 1 ID GS ec 7B 6 IC FS X ? IC FS V 7E •I 7E II 2F / 2F / Note: Codes are in hexadecimal. 486 Apple He Technical Reference German keyboard With the keyboard switch up, the German model of the Apple lie keyboard layout is as shown in Figure E-3, and keystrokes produce the ASCII codes shown in Table E-l. With the keyboard switch down, the German model keyboard layout is as shown in Figure E-7. The change in ASCII code production (from that in Table E-l) is shown in Table E-5. Figure E-7 German keyboard, keyboard switch down esei Ijmm /jiSS /n /© j S % ii / /' ) = ? esc I 2 3 4 5 6 7 8 9 0 8 ' delete •Vr -H Q W E R T Z U 1 0 P U + <3 control A S 0 c u H J K L 0 A # ^ y X c V 8 iV M '. '. - 0 d « •?" -* * f »________ Table E-5 German keyboard code differences from Table E-l Key Key alone + Control •> Shift + Both Code Char Code Char Cod-; Char Code Char 2" 32 2 32 2 22 •i 22 35 33 3 00 NUL 40 5 00 NUL 6& 36 6 36 6 26 & 26 & 7/ 37 7 37 7 2F / 2F / APPENDIX E USA and International Models 487 Table E-5 German keyboard code differences from Table E-l (continued) Key Key alone + Control + Shift • Both Code Char Code Char Code Char Code Char 8( 38 8 38 8 28 ( 28 ( 9) 35 9 39 9 29 ) 29 ) 0= 30 0 30 0 3D = 3D = Is? 7E 6 7F IS 3F J 3F ? U 7D u ID GS 5D u ID GS +• 2B + 2B + 2A • 2A * 0 7C 6 IC FS 5C 0 IC FS A 7B a LB ESC 5B A IB ESC # A 23 # IE RS 5E A IE RS <> 3C < 3C < 3E > 3E > >) i 2C » 3B 1 3B ; 2E 2E 3A 3A Note: Codes are in hexadecimal. Italian keyboard With the keyboard switch up, the Italian model of the Apple lie keyboard layout is as shown in Figure E-3, and keystrokes produce the ASCII codes shown in Table E-l. With the keyboard switch down, the Italian model keyboard layout is as shown in Figure E-8. The change in ASCII code production (from that in Table E-l) is shown in Table E-6. With the keyboard switch up, the Italian model keyboard produces exactly the same ASCII codes for each key, but what is displayed differs for the ten characters indicated with the circled numbers 0, 2-5, and 7-11 in Table E-8. 488 Apple lie Technical Reference Figure E-8 Italian keyboard, keyboard swilch down reset IJSO/IO If lit! /n /© 2 3 4 5 6 7 8 9 0 _ esc & " ' 1 C e 1 £ a e - = delete * **• -H 0 z E R T Y U / 0 P I s «J 0/ 0 control A s 0 E G H J K L M ir § > ' . / ! o < W X C V B N : • b o 0 d * *• .._> i -t APPENDLX.E USA and International Models 489 Table E-6 Italian keyboard code differences from Table E-l Key Key alone + Control + Shift + Both Code Char Code Char Code Char Code Char &1 26 & 26 & 31 1 31 1 II "2 22 22 " 32 2 32 2 1 1 '3 27 27 33 3 33 3 (4 28 ( 28 ( 31 4 31 4 ?5 5C c IC FS 35 5 IC FS e6 7D e 7D e 36 6 36 6 )7 29 ) 29 ) 37 7 37 7 £8 23 £ 23 £ 3S 8 38 8 a9 7B a 7B a 39 9 39 9 60 5D e ID GS 30 0 ID GS |A 7E i IE RS 5E A IE RS $' 24 $ 24 $ 2A * 2A t U% 60 u 60 ii 25 % 25 % 0 §° 40 § 00 NUL 5B IB ESC <> 3C < X < 3E > 3E > 7 i• 2C l 2C i 3F J 5\: j 3B t 3B 2E 2F. :/ 3A 3A 2F / 2F / 6! 7C 6 7C 6 21 1 21 i Note: Codes are in hexadecimal. Western Spanish keyboard With the keyboard switch up, the Western (that is, American) Spanish model of the Apple lie keyboard layout is as shown in Figure E-l, and keystrokes produce the ASCII codes shown in Table E-l. With the keyboard switch down, the Western Spanish model keyboard layout is as shown in Figure E-9. The change in ASCII code production (from that in Table E-l) is shown in Table E-7. 490 Apple He Technical Reference Fitmre E-9 Western Spanish keyboard, keyboard switch down vsei [/•[/•- I IBfi, ''I I «««* /H /Q U' U"" £ S % / d * ( i — + esc ! 2 3 4 5 8 7 8 9 0 — = seiete o ~H n W E B T Y U 1 0 P i control A S 0 F G H J K L N *J 1 9 t n {> Z X C V 8 N M Q 0 o d • < * • • • - > • * * Table E-7 Western Spanish keyboard code differences from Table E-l Key Key alone + Control + Shift + Both Code Char Code Char Code Char Code Char li 31 1 31 I 5B i 5B i H .32 2 .32 2 5D i 5D i 3£ 33 3 33 3 23 £ 23 i 6/ 36 6 36 6 2F / 2F 1 'O ' 0 0 27 27 ' 715 7B 'A 60 ^ 00 NUL 5E A 00 NUL "J 7E - 7F DEL 40 § 7F DEL N 7C h IC FS 5C N IC FS APPENDIX E USA and International Models 491 Table E-7 Western Spanish keyboard code differences from Table E-l (continued) Key Key alone + Control + Shift + Both Code Char Code Char Code Char Code Char 7 2C I 2C 3F J 3F ? 1 i \• 2E 2E 21 1 21 ! i ?" 7D 5 ID GS 22 ID GS <> 3C < IE RS 3E > IE RS Note: Codes are in hexadecimal. ASCII character sets Table E-8 lists the ASCII (American National Standard Code for Information Interchange) codes that the Apple He family uses for the English (USA) character set. Characters that are different in other character sets are marked with an asterisk; the alternate characters are shown in Table E-9. 492 Apple lie Technical Reference • Table E-8 ASCII codes for the English (USA) character set ASCII Dec Hex ASCII Dec Hex ASCII Dec Hex ASCII Dec Hex dor code code diar code code dnr code code char code code NUL 00 CO SP .32 20 64 40 *• 60 9' % SOH 01 01 1 33 21 A 65 41 a 97 61 f STX 02 02 II 34 22 B 66 42 b S 62 ETX 1)3 05 #• 35 23 C 67 43 c 99 63 EOT 04 04 $ 36 24 I) 68 44 d 100 64 ENQ 05 05 % 37 25 E ft) 45 e 101 65 ACK 06 06 & 38 26 I- 70 46 f 102 66 1 BEL 07 07 39 27 G 71 47 g 103 67 BS 08 08 ( 40 28 11 72 48 h 104 63 HT 09 09 ) 41 29 I 73 49 i i in- 69 LF 10 OA • 42 2A J 74 4A 1 itio 6A VT II 0B + 43 2B K 75 4B k 107 6B FF 12 0C 1 44 2C 1. 76 4C 1 108 6C OR 13 0D - 45 2D M 77 4D m 109 6D SO li 0E 46 2E N 78 4E n 110 6E SI 15 OF / 47 21' O 79 4F 0 111 6F DLE 16 10 0 48 30 P 80 50 P 112 70 DC1 17 11 1 49 31 Q 81 51 q 113 71 DC2 18 12 2 ^J 32 R 82 52 r 114 72 DC3 19 13 3 51 33 S 83 53 S 115 73 DC4 20 14 4 52 3. T 84 54 t 116 74 NAK 21 15 5 53 35 U 85 5S u 117 75 SYN 22 16 6 54 36 V 86 56 V 118 76 ETB 23 17 7 55 37 w 87 57 w 119 77 CAN 24 18 8 56 38 X 88 >8 X 120 78 E.M 25 19 9 57 39 Y 89 59 y 121 79 SUB 26 1A >8 3A Z 90 5A z 122 7A ESC 27 IB i 59 3B [' 91 5B {• 123 7B FS 28 IC < CO 3C V 92 5C 1' 124 7C GS 29 ID = 61 3D 1' 93 5D }• 125 7D RS 30 IE > 62 3E A 94 5E _• 126 7E US 31 IF p 63 3F 95 5F DEL 127 7F ' The characters marked with an asterisk are not the same in all character sets. The differences are shown in Table E-9. APPENDIX E USA and Iniemational Models 493 Table E-9 Differences from English (USA) character set Hexadecimal ASCII Codes 23 40 5B 5C 5D 60 7B 7C 7D 7E English (USA) * 9 [ \ 1 * { 1 ) English (UK) i 9 [ \ 1 1 1 ) German # 5 A 0 U * a 6 ii French I a o * 6 U e ? 5 0 Italian £ § ? e U a 6 e 0 Spanish i 5 i N i * n C Power supply specifications The basic specifications of the power supply furnished with the Apple lie for use in Europe and other countries having 50 Hz alternating current are shown in Table E-10. • Table E-10 50 Hz power supply specifications Line voltage 199 to 255 VAC, 50 Hz Maximum input power consumption 25 W Supply voltage +15 VDC (nominal) Supply current 1.2 A (nominal) 494 Apple He Technical Reference Appendix F Firmware Entry Points This appendix lists and describes the firmware entry points available for your use in the Apple lie family of computers. Only the entry points described in this appendix are supported by Apple Computer, Inc.; if you use any other firmware routines or entry points for firmware routines, your program will almost certainly fail the next time the firmware is revised. The firmware routines in this appendix are presented in sequence of their entry points. For your convenience, Table F-l lists the routines alphabetically by name and briefly summarizes the function of each. Firmware routines for enhanced video firmware I/O are described in the section "I/O Firmware Support for Video Output" in Chapter 6. • 495 Table F-l Summary of firmware entry points Routine Entry point Function Advance SFBF4 Advance the cursor Applell SFB60 Clear text screen and display name of machine BasCalc $FBC1 Calculate base address for a line on the text screen Bell SFF3A Generate a tone for 0.1 second preceded by a 0.01 second delay Belli SFBDD Send a bell character to standard output Belll.2 $FBE2 Generate a tone for 0.1 second with no delay Bell2 SFBE4 Generate a tone for a specified amount of time Break SFA4C 6502 break handler BS $FC10 Backspace the cursor ClrEOL SFC9C Clear line of text from cursor to end of line ClrEOLZ $FC9E Clear line of text from column in Y register to end of line ClrEOP SFC42 Clear text window from cursor to bottom of window ClrScr SF832 Clear the Lo-Res graphics display to black ClrTop $F836 Clear the top 40 lines of the Lo-Res graphics display COut SFDED Call the standard output routine COutl $FDF0 Send text to the screen; default routine used for standard output COutZ $FDF6 Alternate entry point to COutl CR SFC62 Move cursor to beginning of next line CROut $FD8E Send a carriage return to standard output CROutl $FD8B Clear to end of line and send carriage return to standard output Dig $FF8A Convert an ASCII number into a hexadecimal digit and store in A2L/A2H FD10 $FD10 Jump to standard input GBasCalc $F847 Calculate the base address for a row on the Lo-Res graphics screen GetLn $FD6A Display standard prompt and read a line of text GetLnO SFD6C Display prompt in A register and read a line of text GetLnl SFD6F Read a line of text GetLnZ $FD67 Send CR to standard output, display standard prompt, and read a line of text GetNum $FFA7 Scan input buffer; decode ASCII numbers and store them in A2L/A2H Go $FEB6 Set registers to stored values and jump to address in A1L/A1H HeadR SFCC9 Obsolete entry point HLine $F819 Draw a horizontal line of blocks on the Lo-Res graphics screen Home $FC58 Move cursor to upper left corner and clear to bottom of text window 496 Apple He Technical Reference Table F-l Summary of firmware entry points (continued) Routine Entry Point Function IDRouline $FE1F Apple IIGS ID routine Init $FB2F Initialize the text screen InPorl $FESB Set input hooks to point to a specified port InsDsl.2 $F88C Load A register with an opcode and call lnsDs2 InsDs2 $I;88E Determine the length of a 6502 instruction InstDsp $F8D0 Disassemble and display an instruction IORTS $FF58 Known RTS instruction KbdWait $FB88 Wait for a keypress Keyln $FD1B Read the keyboard; default routine used for standard input KeylnO $FD18 Jump to standard input LF $FC66 Move cursor down one line List 5FE5E Disassemble and print 20 instructions Mon $FF65 Sound speaker and enter the Monitor Monz $FF69 Enter the Monitor; standard Monitor entry point Monz4 SFF70 Enter the Monitor after your program has read a line of text Move SFE2C Copy the contents of memory from one range of locations to another NewBrk SFA47 Alternate entry point to BREAK NxtAl SFCBA Compare A1L/A1H with A2L/A2H and increment A1L/A1H NxtA4 SFCB4 Increment A4L/A4H NxtChr SFF AD Test character in the input buffer and send to Dig if it is a number NxtCol $F85F Increment the value of COLOR by 3 OldBrk $FA59 Break routine called by BREAK OldlRQ $FA40 Jump to interrupt-handling routine OldRst SFF59 Initialize input, output, and text screen, and enter Monitor OutPort $FE95 Set output hooks to point to a specified port PCAdj $1-953 Load the Monitor's PC into the A and Y registers, and increment the value Plot $F800 Plot a block on the Lo-Res graphics screen at the location you specify Plotl $I:80E Plot a block on the Lo-Res graphics screen on the current line PrAl $1-1)92 Send a CR, contents of A1L/A1H, and a hyphen to standard output PrB12 $F94A Print the number of blank spaces specified by the X register PrBlnk $F948 Print three blank spaces PrByte $FDDA Print the contents of the A register APPENDIX F Firmware Entry Points 497 Table F-l Summary of firmware entry points (continued) Routine Entry Point Function PRead $FB1E Read the dial on a hand control PRead4 $FB2i Alternate entry point of PRead PrErr SFF2D Print "ERR" and send a bell character to standard output PrHex $FDE3 Print the lower nibble of the A register PrntAX SF941 Print the contents of the A and X registers PrntX $F944 Print the contents of the X register PrntYX $F940 Print the contents of the Y and X registers PwrUp $FAA6 Cold-start initialization routine RdChar $FD35 Set Escape mode to active and jump to RdKey RdKey SFDOC Place character in A register and jump to standard input Read SFEFD Obsolete entry point RegDsp $FAD7 Display Monitor register contents stored in memory Reset $FA62 Reset handler Restore SFF3F Set registers to stored values Save $FF4A Store in memory Lhe contents of the registers Scrn SF871 Return the color value of a block on the Lo-Res graphics display Saoll SFC70 Scroll characters in text window up one line SetCol $F864 Set the color used for plotting in the Lo-Res graphics mode SetGr $FB40 Set display to mixed graphics mode Setlnv SFE80 Set inverse flag to display inverse characters SetKbd $FE89 Set input hooks to point to Keyln SelNorm $FE84 Set inverse flag to display normal characters SetPwrC SFB6F Set Validity-Check byte SetTxt SFB39 Initialize text screen; don't force text Page 1 SetVid $FE93 Set output hooks to point to COutl SetWnd SFB4B Set the size of the text window StorAdv $FBF0 Place a printable character on the text screen TabV $FB5B Vertical tab to line specified in A register; update CV Up $FC1A Move the cursor up one line 498 Apple lie Technical Reference Table F-l Summary of firmware entry points (continued) Routine Entry Point Function Verify $FE36 Compares the contents of two ranges of memory Version $FBB3 Identification byte VidOut SFBFD Send a character to StorAdv; handle CR, LF, BS, and BEL characters VidWait SFB78 Pause output when Control-S is pressed VLine SF828 Draw a vertical line of blocks on the Lo-Res graphics screen VTab SFC22 Vertical tab to line specified by CV VTabZ SFC24 Vertical tab to line specified in A register; don't update CV Wait $FCA8 Delay loop Write SFECD Obsolete entry point ZIDByte SFBCO Identification byte ZlDByte2 $FBBF Identification byte ZMode $FFC7 Store $00 in Monitor's Mode byte APPENDIX F Firmware Entry Points 499 $F800 Plot Description This routine puts a single block of the color value set by SetCol on the Lo-Res graphics display screen at the location you specify. Input Registers A = block's vertical position ($00-$2F) X = any value Y = block's horizontal position (S0O-S27) Memory COLOR (address $30) = color value set by SetCol Output Registers A = undefined X = unchanged Y = unchanged P = undefined See also SetCol "Lo-Res Graphics" in Chapter 6 "Display Page Maps" in Chapter 6 500 Apple He Technical Reference $F80E Plotl Description This routine puts a single block of the color value set by SetColon the Lo-Res graphics display screen at the horizontal position you specify on the current row. The current row is determined by the values stored in locations GBASL/GBASH. Use Plot if you want to input both the vertical and horizontal positions. Use GBasCalc to set GBASL and GBASH for a particular vertical position. Input Registers A = any value X = any value Y = block's horizontal position ($00-S27) Memory COLOR (address $30) = color value set by SetCol Output Registers A = undefined r X = unchanged Y • unchanged P = undefined See also GBasCalc Plot SetCol "Lo-Res Graphics" in Chapter 6 "Display Page Maps" in Chapter 6 APPENDIX F Firmware Entry Points 501 1 $F819 HLine Description This routine draws a horizontal line of blocks on the Lo-Res graphics display screen, lhe color of the blocks is determined by COLOR, which you can set with the SetCol routine. Input Registers A = block's vertical position ($00-$2F) X = any value Y = horizontal position of leftmost block ($00-$27) Memory 112 (address $2C) = horizontal position of rightmost block ($00-$27) COLOR (address $30) = color value set by SetCol Output Registers A = undefined X = unchanged Y = undefined P = undefined See also SetCol "Lo-Res Graphics" in Chapter 6 "Display Page Maps" in Chapter 6 502 Apple lie Technical Reference $F828 VLine Description This routine draws a vertical line of blocks on the Lo-Res graphics display screen. The color of the blocks is determined by COLOR, which you can set with the SetCol routine. Input Registers A = vertical position of top block ($00-$2F) X = any value Y = block's horizontal position ($00-$27) Memory V2 (address $2D) = vertical position of bottom block ($00-$2F) COLOR (address $30) = color value set by SetCol Output Registers A = undefined X = unchanged Y = undefined P = undefined See also SetCol "Lo-Res Graphics" in Chapter 6 "Display Page Maps" in Chapter 6 APPENDIX F Firmware Entry Points 503 $F832 ClrScr Description This routine clears the Lo-Res graphics display to black. • Note-. If you call this routine while the video display is in text mode, the routine fills the screen with inverse at-sign (@) characters. Input Registers A = any value X = any value Y = any value Output Registers A = undefined X = unchanged Y = undefined P = changed See also "Lo-Res Graphics" in Chapter 6 504 Apple He Technical Reference $F836 ClrTop Description This routine clears the top 40 lines of the Lo-Res graphics display to black. You can use this routine to clear the graphics portion of the mixed-mode screen. Input Registers A = any value X = any value Y = any value Output Registers A = undefined X = unchanged Y = undefined P = changed See also "Mixed-Mode Displays" in Chapter 6. APPENDLX F Firmware Entry Points 505 $F847 GBasCalc This routine calculates the starting address in memory (the base address) of the data for a Description specific row on the Lo-Res graphics screen. This address is stored at GBASL'GBASH. » Registers A • vertical position of the row (S00-S2F) Input X = any value Y = any value Output Registers A = the value stored in GBASL X = unchanged Y = unchanged P = undefined See also Plotl "Graphics Modes" in Chapter 6 "Display Page Maps" in Chapter 6 506 Apple lie Technical Reference $F85F NxtCol Description This routine adds 3 to the current color used for Lo-Res graphics. Use SetCol to set a specific color for Lo-Res graphics. Input Registers A = any value X = any value Y = any value Memory COLOR (address $30) = current color value Output Registers A = new value for color, same number in both nibbles X = unchanged Y = unchanged P = undefined Memory COLOR (address $30) = new color value See also SetCol "Lo-Res Graphics" in Chapter 6 APPENDIX F Firmware Entry Points 507 $F864 SetCol Description This routine sets the color used for plotting in the Lo-Res graphics mode. The colors are shown in Table F-2. Table F-2 Lo-Res graphics colors Nibble value Color Dec Hex 0 $00 Black 1 $01 Magenta 2 502 Dark blue 3 $03 Purple 4 $04 Dark green 5 $05 Gray 1 6 $06 Medium blue 7 $07 Light blue 8 $08 Brown 9 $09 Orange 10 $0A Gray 2 11 SOB Pink 12 $oc Light green 13 $0D Yellow 14 S0E Aquamarine 15 50F White Note: Colors may vary, depending on adjustment of monitor or television set. Input Registers A • new color in low nibble; high nibble can be any value X =• any value Y = any value 508 Apple He Technical Reference Output Registers A = new color; same number in both nibbles X = unchanged Y = unchanged P = undefined Memory COLOR (address $30) = new value for color See also "Lo-Res Graphics" in Chapter 6 APPENDIX F Firmware Entry Points 509 $F871 Scrn Description This routine returns the color value of a single block on the Lo-Res graphics display. Input Registers A - block's vertical position ($0O-$2F) X = any value Y = block's horizontal position ($00-$27) Output Registers A = color of specified block in low nibble; high nibble = 0 X • unchanged Y = unchanged P = undefined See also "Lo-Res Graphics" in Chapter 6 510 Apple lie Technical Reference $F88C InsDsl.2 Description lhe instruction at this address loads the A register with an opcode, the length of which is calculated by the InsDs2 routine. The opcode is loaded by an LDA (PCL, X) instruction. Immediately after executing this instruction, the CPU executes the InsDs2 routine. Input Registers A = any value X = offset into buffer that contains pointers to instructions Y = any value Memory PCl/PCH (addresses $3A-$3B) = address of start of buffer Output Registers A = opcode for evaluation by InsDs2 X = undefined Y = $00 P = undefined Memory LENGTH (address $2F) = length - 1 of 6502 instruction, or = $00 if the A register does not contain a 6502 opcode See also InsDs2 APPENDIX F Firmware Entry Points 511 $F88E InsDs2 Description This routine determines the length (minus 1) of the 6502 instruction specified by the opcode stored in the A register (accumulator). You can use the InsDsl.2 entry point to load an opcode into the A register. A Important The InsDs2 routine returns the correct instruction length for 6502 opcodes only. All other opcodes return a length of $00. The BRK opcode returns a length of $00. A Input Registers A = opcode to be evaluated X = any value Y = any value Output Registers A = undefined X = undefined Y=$00 P = undefined Memory LENGTH (address $2F) = length - 1 of 6502 instruction, or = $00 if the A register does not contain a 6502 opcode See also InsDsl.2 512 Apple He Technical Reference $F8D0 InstDsp Description This routine disassembles and prints to standard output the instruction pointed to by the address in PCL/PCH. Input Registers A = any value X = any value Y = any value Memory PCI7PCH (addresses $3A-$3B) = pointer to opcode Output Registers A = undefined X = undefined Y = undefined P = changed See also "Standard Output Routines" in Chapter 4 "Disassembled Programs" in Chapter 10 APPENDIX F Firmware Entry Points 513 $F940 PrntYX Description This routine calls the PrByte routine to print to standard output the contents of the Y and X registers as a four-digit hexadecimal value. The X register is printed as the low byte and the Y register is the high byte. Input Registers A = any value X = low byte of the value to be printed Y = high byte of the value to be printed Output Registers A = undefined X = unchanged Y = unchanged P = changed See also PrByte "Standard Output Routines" in Chapter 4 514 Apple lie Technical Reference $F94l PrntAX Description This routine prints to standard output the contents of the A and X registers as a four- digit hexadecimal value. The X register is printed as the low byte and the A register is the high byte. Input Registers A = high byte of the value that is printed X = low byte of the value that is printed Y = any value Output Registers A • undefined X = unchanged Y • unchanged P = changed See also "Standard Output Routines" in Chapter 4 APPENDIX F Firmware Entry Points 515 $F944 PrntX Description This routine prints to standard output the contents of the X register as a two-digit hexadecimal value. Input Registers A = any value X = the value that is printed Y = any value Output Registers A = undefined X = unchanged Y = unchanged P = changed See also "The Standard I/O Links" in Chapter 4 "Standard Output Routines" in Chapter 4 516 Apple He Technical Reference $F948 PrBlnk Description This routine prints three blank spaces to standarc Input Registers A = any value X = any value Y = any value Output Registers A = $00 X = $A0 (the ASCII Space character) Y = unchanged P = undefined See also "The Standard I/O Links" in Chapter 4 "Standard Output Routines" in Chapter 4 APPENDIX F Firmware Entry Points 517 $F94A PrBl2 Description This routine prints to standard output the number of blank spaces specified by the value in the X register. You can print from 1 to 256 spaces with this routine. Input Registers A = any value X = the number of spaces to print, from $01-$FF; $00 prints 256 spaces Y = any value Output Registers A = $00 X = SAO (the ASCII Space character) Y = unchanged P = undefined See also "The Standard I/O Links" in Chapter 4 "Standard Output Routines" in Chapter 4 518 Apple He Technical Reference $F953 PCAdj Description This routine reads from memory the value of the Monitor's program counter, loads the low byte (PCL) into the A register, loads the high byte (PCH) into the Y register, and increments the value in the A and Y registers by 1 to 4. The LENGTH location in zero page (address $2F) contains 1 less than the amount by which PCL/PCH is to be incremented. For example, if LENGTH = 2, then 3 is added to PCL/PCH. • Note: The Monitor's program counter (PCL/PCH) in memory is not changed by the PCAdj routine; the incremented value is available only in the A and Y registers at the end of this routine. Input Registers A = any value X = any value Y = any value Memory PCL/PCH (addresses $3A-$3B) = Monitor's program counter LENGTH (address $2F) = 1 less than the value to add to PCL/PCH; 0 to 3 Output Registers A = new PCL X = undefined Y = new PCH P = undefined Memory PCL = unchanged PCH = unchanged APPENDIX E Firmware Entry Points 519 $FA40 OldlRQ Description This routine jumps to the interrupt-handling routine in ROM. The interrupt-handling routine saves the memory state of the machine, checks for an internal interrupt, and then calls the user's interrupt handler at $03FE. Input Registers A = any value X = any value Y = any value Output Registers A = unchanged X = unchanged Y = unchanged P = unchanged Memory A5H (address $45) = value in A register before IRQ interrupt See also "User's Interrupt Handler at $03FE" in Chapter 3 520 Apple He Technical Reference $FA47 NewBrk Description This routine stores the A register (accumulator) in memory location MACSTAT (address $44) and pulls values for the Y, X, and A registers from the stack before passing control to the Break routine. • Note: Normally, NewBrk is called by the interrupt handler, which has set the hardware to its default state and encoded the memory state of the machine in the A register. The encoding scheme for the memory state is listed in the section "Handling Break Instructions" in Chapter 3. Input Registers A = memory state of the machine X = any value Y = any value Output Registers A = third value from stack X = second value from stack Y = first value from stack P = unchanged Memory MACSTAT (address $44) = memory state of the machine See also Break "Handling Break Instructions" in Chapter 3 APPENDIX F Firmware Entry Points 521 $FA4C Break Description This routine is the 65C02 break handler. Break saves in memory the 65C02 registers and the program counter, and then jumps to the routine pointed to by the user hook at 503F0- 503F1. The default address for this pointer is $FA59, the OldBrk routine. Input Registers A = any value X = any value Y = any value Memory $45) = the value in the A register before the break A5H (address 5 Output Registers A = undefined X = undefined Y = undefined P = undefined Memory A5H (address $45) = the value in the A register when break occurred XREG (address $46) = the value in the X register when break occurred YREG (address $47) = the value in the Y register when break occurred STATUS (address $48) = the value in the P register when break occurred SPNT (address $49) = the value in the stack pointer when break occurred PCL/PCH (addresses $3A-3B) = address of the program counter when break occurred earlier See also OldBrk "Handling Break Instructions" in Chapter 3 522 Apple He Technical Reference $FA59 OldBrk Description This routine prints the values for the program counter and registers that are stored in zero page, then jumps to the Monitor. Input Registers A = any value X = any value Y = any value Memory A5H (address $45) = the value in the A register before the break XREG (address $46) = the value in the X register before the break YREG (address $47) = the value in the Y register before the break STATUS (address $48) = the value in the P register before the break SPNT (address $49) = the value in the stack pointer before the break PCL/PCH (addresses S3A-3B) = address of the program counter before the break Output Registers A = undefined X = undefined Y = undefined P = undefined See also "Handling Break Instructions" in Chapter 3 APPENDIX F Firmware Entry Points 523 $FA62 Reset Description This routine is called by the 65C02 reset vector at $FFFC-$FFFD. The Reset routine performs a warm start initialization, then checks to see if a cold start is required. If the Command key was pressed during reset or if the user reset vector is not valid, the routine jumps to the cold-start routine, PwrUp. If this reset is a normal warm start, then Reset jumps to the address pointed to by the user interrupt vector at $03F2-$03F3. Input Registers A = any value X = any value Y = any value Memory SOFTEV (address 03F2-O3F3) = pointer to routine to be executed after a warm start PWREDUP (address 03F4) = Validity-Check byte, used to check SOFTEV for validity Output The Reset routine does not return to the calling program. See also PwrUp "Starts and Resets" in Chapter 3 524 Apple He Technical Reference $FAA6 PwrUp Description This routine completes the initialization of the machine necessary for a cold start. The PwrUp routine is called by the Reset routine when either the Command key is pressed along with the Control and Reset keys, or the reset vector is not valid (the power-up bytes do not match). PwrUp sets some soft switches, writes 2 bytes of meaningless data into the beginning of each page of main RAM, and passes control to the firmware for the first startup device. If the firmware cannot find any startup routine in any startup device, it displays a message on the screen and passes control to Applesoft. Input Registers A = any value X = any value Y = any value Output The PwrUp routine does not return to the calling program. See also Reset "Starts and Resets" in Chapter 3 APPENDIX F Firmware Entry Points 525 $FAD7 RegDsp Description This routine displays the memory state of the machine stored in MACSTAT (address $44) plus the A, X, Y, P, and S register contents stored by the firmware. This information is stored by the Break routine before jumping to the routine pointed to by the user hook at $03F0-$03F1. The encoding scheme for the memory slate is listed in the section "Handling Break Instructions" in Chapter 3. Input Registers A = any value X = any value Y = any value Memory MACSTAT (address $44) = memory state of the machine A5H (address $45) = A register value XREG (address $46) = X register value YREG (address $47) = Y register value STATUS (address $48) = P register value SPNT (address $49) = stack pointer value Output Registers A = undefined X = undefined Y = undefined P = undefined See also "Handling Break Instructions" in Chapter 3 526 Apple He Technical Reference $FB1E PRead Description This routine returns a number ($00 to $FF) in the Y register that indicates the position of the dial on a hand control (game paddle). You use the X register to specify which hand control should be read. PRead reads the mouse position in place of the game paddle if a mouse is connected, turned on, and in transparent mode, If X = 0, PRead returns the X position of the mouse in the Y register; if X = 1, PRead returns the Y position of the mouse. Input Registers A = any value X = hand control to be read; 0 or 1 Y = any value Output Registers A = undefined X = unchanged Y = position of hand control dial, $00-$FF P = undefined See also "Game Input" in Chapter 9 "Using the Mouse As a Hand Control" in Chapter 9 APPENDIX F Firmware Entry Points 527 $FB21 PRead4 Description This routine is identical to the PRead routine, except that PRead4 does not read the mouse position if a mouse is connected to the game port. Input Registers A = any value X = hand control to be read; 0 or 1 Y = any value Output Registers A = undefined X = unchanged Y = position of hand control dial, $00-$FF P = undefined See also PRead "Game Input" in Chapter 9 528 Apple lie Technical Reference $FB2F Init Description This routine initializes the text screen: it sets the display page to text Page 1 and sets the display to a full-screen text window display. Init also calls BasCalc to calculate the starting address in memory (the base address) of the data for the last line of text on the text screen; BasCalc stores this address in BASL/BASH. Input Registers A = any value X = any value Y = any value Output Registers A = low byte of base address X = undefined Y = undefined P = undefined Memory BASL/BASH (address $28-$29) = base address of last line in window See also BasCalc "Text Modes" in Chapter 6 "Display Page Maps" in Chapter 6 APPENDIX F Firmware Entry Points 529 $FB39 SetTxt Description This routine sets the display to a full-screen text window display. SetTxt also calls BasCalc to calculate the starting address in memory (the base address) of the data for the last line of text on the text screen; BasCalc stores this address in BASL/BASH. SetTxt is identical to the Init routine, except that SetTxt does not set the display page to text Page 1. Input Registers A = any value X = any value Y = any value Output Registers A = low byte of base address X = undefined Y = undefined P = undefined Memory BASL/BASH (address $28-$29) = base address of last line of text See also BasCalc Init "Text Modes" in Chapter 6 "Display Page Maps" in Chapter 6 530 Apple He Technical Reference $FB40 SetGr Description This routine sets the display to mixed graphics mode, clears the graphics portion of the screen, and sets the top of the text window to line 20. SetGr also calls BasCalc to calculate the starting address in memory of the data for the last line of text on the screen; BasCalc stores this address in BASL/BASH. Input Registers A = any value X = any value Y = any value Output Registers A = low byte of base address X = undefined Y = undefined P = undefined Memory BASL/BASH (address $28-$29) = base address of last line of text See also BasCalc "Mixed-Mode Displays" in Chapter 6 APPENDLX F Firmware Entry Points 531 $FB4B SetWnd Description This routine sets the text window to the full width of the screen, with the bottom of the window at the bottom of the screen and the top of the window at the value passed in the A register. SetWnd also calls BasCalc to calculate the starting address in memory (the base address) for the last line of text in the window; BasCalc stores this address in BASL/BASH. Input Registers A = top of text window ($00-$ 17) X = any value Y • any value Output Registers A = low byte of base address X = unchanged Y = undefined P = undefined Memory WNDLFT (address $20) = $00 WNDWDTH (address $21) = $28 for 40-column display, $50 for 80-column display WNDTOP (address $22) = value passed in the A register WNDBTM (address $23) = $18 BASJVBASH (address $28-$29) = base address of last line of text See also "The Text Window" in Chapter 4 532 Apple lie Technical Reference $FB5B TabV Description This routine performs a vertical tab to the line specified by the value in the A register. TabV calls BasCalc to calculate the starting address in memory (the base address) for the text-page line specified by the value in the A register. BasCalc stores this address in BASL/BASH, effectively moving the cursor. TabV differs from VTab and VTabz in that TabV stores the new line number in CV. Input Registers A = line number ($00-$17) X = any value Y = any value Output Registers A = low byte of base address X = unchanged Y = undefined P = undefined Memory CV (address $25) = line number passed in A register BASL/BASH (address $28-$29) = base address for specified line See also VTab VTabz "Standard Output Routines" in Chapter 4 "Text Modes" in Chapter 6 "Display Page Maps" in Chapter 6 APPENDK F Firmware Entry Points 533 $FB60 Apple!! Description This routine clears the text screen and displays the siring "Apple He" or "Apple lie +" on the first line of the screen. This routine does not work when the display is set to graphics or mixed mode. Input Registers A = any value X = any value Y = any value Output Registers A = undefined X = unchanged Y = undefined P = changed See also "Text Modes" in Chapter 6 534 Apple He Technical Reference $FB6F SetPwrC Description This routine calculates the Validity-Check byte for the current reset vector and stores it in memory. Input Registers A = any value X = any value Y = any value Memory SOFTEV + 1 (address $03F3) = the high byte of the reset vector Output Registers A = the Validity-Check byte X - unchanged Y = unchanged P = undefined Memory PWREDUP (address $03F4) = the Validity-Check byte See also "The Reset Vector" in Chapter 3 APPENDLX F Firmware Entry Points 535 $FB78 VidWait Description This routine checks to see if the A register contains the value $8D (a carriage return); if it does, VidWait checks the keyboard for a Conlrol-S character ($93). If it finds a Control-S, VidWait clears the keyboard strobe and passes control to KbdWait, which causes the output to pause. If it does not find a Control-S, VidWait checks to see if the enhanced video firmware is active. If enhanced video firmware is not active, VidWait passes control to VidOut, which handles the standard control-character functions, prints the next character, and advances the cursor. If the enhanced video firmware is active, VidWait passes control to a routine that handles the enhanced video control-character functions, prints the next character, and advances the cursor. VidWait ignores all input from the keyboard other than Control-S. Input Registers A = the next character to be printed X = any value Y = any value Output Registers A = undefined X = unchanged Y = undefined P = undefined See also "Standard Output Routines" in Chapter 4 536 Apple He Technical Reference $FB88 KbdWait Description This routine waits for a keypress. When a key has been pressed, KbdWait checks to see if it is a Control-C. If the character is not a Control-C, KbdWait clears the keyboard strobe and passes control to VidOut, which prints the character in the A register. If the character is a Control C, KbdWait passes control directly to VidOut, without clearing the keyboard strobe. Input Registers A = the next character to be printed X = any value Y = any value Output Registers A = undefined X = unchanged Y = undefined P = undefined See also "The Stop-List Feature" in Chapter 4 APPENDIX F Firmware Entry Points 537 $FBB3 Version Description This location contains one of the identification bytes for the ROM. Version is not a callable routine. The value of this byte is S06 for all Apple He computers. Input This is not a callable routine. Output This is not a callable routine. See also "Machine Identification" in Appendix D 538 Apple He Technical Reference $FBBF ZIDByte2 Description This location contains one of the identification bytes for the ROM. ZIDByte2 is not a callable routine. The value of this byte depends on the version of Apple lie computer, as shown in Table F-3. Table F-3 Values of Apple He identification byte Machine $FBBF Apple He (original) $FF Apple lie (UniDisk 3.5) $00 Apple lie (memory expansion) $03 Apple He Plus $05 Input This is not a callable routine. Output This is not a callable routine. See also "Machine Identification" in Appendix D APPENDIX F Firmware Entry Points 539 $FBCO ZIDByte Description This location contains one of the identification bytes for the ROM. ZIDByte is not a callable routine. The value of this byte is $00 for all Apple lie computers. Input This is not a callable routine. Output This is not a callable routine. See also "Machine Identification" in Appendix D 540 Apple He Technical Reference $FBC1 BasCalc Description This routine calculates the starting address in memory (base address) for the line on the text screen specified by the value in the A register. BasCalc stores the address at BASL/BASH. Input Registers A = line number (SO0-S17) X = any value Y = anv value Output Registers A = low byte of base address X = unchanged Y = unchanged P = undefined Memory BASL/BASH (address $28-$29) = base address for specified line See also "Text Modes" in Chapter 6 "Display Page Maps" in Chapter 6 APPENDIX F Firmware Entry Points 541 $FBDD Belli Description This routine clicks the speaker at 1 kHz for 0.1 second to generate a tone. There is a 0.01 second delay before the lone is generated to prevent rapid calls to Belli from causing distorted sounds. Input Registers A = any value X = any value Y = any value Output Registers A = undefined X = unchanged Y = $00 P = undefined See also Belll.2 Bell2 "Speaker Output" in Chapter 5 542 Apple lie Technical Reference $FBE2 Belll.2 Description This routine clicks the speaker at 1 kHz for 0.1 second to generate a tone. Belll.2 differs from Belli in that Belll.2 has no delay before the tone is generated. Input Registers A = any value X = any value Y = any value Output Registers A = undefined X = unchanged Y = $00 P = undefined See also Belli Bell2 "Speaker Output" in Chapter 5 APPENDIX F Firmware Entry Points 543 $FBE4 Bell2 Description This routine clicks the speaker repeatedly to generate a 1 kHz square-wave tone; each two clicks constitute one cycle. The duration of the tone depends on the value passed in the Y register. A value of $C0 in the Y register toggles the speaker 192 times, generating a tone for approximately 0.1 second. A value of $00 in the Y register toggles Lhe speaker 256 times. Input Registers A = any value X = any value Y = number of times to click speaker (duration of tone = 0.001 Y/2) Output Registers A = undefined X = unchanged Y = $00 P = undefined See also Belli Belll.2 "Speaker Output" in Chapter 5 544 Apple He Technical Reference $FBFO StorAdv Description This routine places a printable character on the text screen. The character is placed on the line determined by the value in BASLatthe horizontal position determined by the value in CH. After printing the character, StorAdv increments CH to advance the cursor. If CH + 1 exceeds the window width (stored in WNDWDTH), StorAdv executes a carriage return. Input Registers A = character to display X = any value Y = any value Memory WNDWDTH (address $21) = window width CH (address $24) = horizontal position of character BASL/BASH (address $28-$29) = base address of current line of text Output Registers A = undefined X = unchanged Y = undefined P = undefined Memory CH = previous value of CH + 1 See also "Standard Output Routines" in Chapter 4 "Text Modes" in Chapter 6 "Display Page Maps" in Chapter 6 APPENDIX F Firmware Entry Points 545 $FBF4 Advance Description This routine increments the value stored in CH by 1, advancing the cursor. If CH + 1 exceeds the window width (stored in WNDWDTH), Advance executes a carriage return. Input Registers A = any value X = any value Y = any value Memory WNDWDTH (address $21) = window width CI I (address $24) = horizontal position of cursor Output Registers A = undefined X • unchanged Y = undefined P = undefined Memory CH = previous value of CH + 1 See also "Standard Output Routines" in Chapter 4 "Text Modes" in Chapter 6 "Display Page Maps" in Chapter 6 546 Apple He Technical Reference $FBFD VidOut Description This routine sends printable characters to StorAdv. VidOut also checks for carriage returns, line feeds, backspaces, and bell characters (Control-G); if it finds one of these characters, VidOut branches to the appropriate routine to handle it. VidOut ignores all other control characters. Input Registers A = character to display X = any value Y = any value Output Registers A = character to display or control character to process X = unchanged Y = undefined P = undefined See also StorAdv "Standard Output Routines" in Chapter 4 APPENDIX F Firmware Entry Points 547 $FC10 BS Description This routine executes a back space. BS decrements the value in CH by one; if the cursor is at the left edge of the window, CH is set to the right edge of the window and BS branches to the Up routine. Input Registers A = any value X = any value Y = any value Memory WNDLFT (address $20) = left edge of text window WNDWDTH (address $21) = text window width CH (address $24) = horizontal position of cursor Output Registers A = undefined X = unchanged Y = undefined P = undefined Memory CH = previous value of CH - 1 See also "Standard Output Routines" in Chapter 4 "Text Modes" in Chapter 6 "Display Page Maps" in Chapter 6 548 Apple He Technical Reference $FC1A Up Description This routine decrements the value CV by 1, moving the cursor up one line, unless the cursor is currently on the top line of the window. Input Registers A = any value X = any value Y = any value Memory WNDTOP (address $22) = top of window CV (address $25) = vertical position of cursor Output Registers A = undefined X = unchanged Y = unchanged P = undefined Memory CV = previous value of CV - 1 (unless at top of window) See also "Standard Output Routines" in Chapter 4 "Text Modes" in Chapter 6 "Display Page Maps" in Chapter 6 APPENDLX F Firmware Entry Points 549 $FC22 VTab Description This routine performs a vertical tab to the line specified by the value stored in CV. VTab calls BasCalc to calculate the starting address in memory (the base address) for the text- page line specified by the value stored in CV. BasCalc stores this address in BASL/BASH, effectively moving the cursor. VTab differs from TabV in that VTab does not store a new line number in CV. Input Registers A = any value X = any value Y = any value Memory CV (address $25) = line number to which cursor is moved ($00-$17) Output Registers A • low byte of base address X = unchanged Y = unchanged P = undefined Memory BASL/BASH (address $28-$29) = base address for specified line See also TabV VTabz "Standard Output Routines" in Chapter 4 "Text Modes" in Chapter 6 "Display Page Maps" in Chapter 6 550 Apple He Technical Reference $FC24 VTabz Description This routine performs a vertical Lab to the line specified by the value stored in the A register (accumulator). VTabz calls BasCalc to calculate the starting address in memory (the base address) for the text-page line specified by the value stored in the A register. BasCalc stores this address in BASL/BASFi, effectively moving the cursor. VTabz differs from TabV in that it does not store the line number in CV; it differs from VTab in that it does not read the line number from CV. Input Registers A - line number ($00-$ 17) X = any value Y = any value Output Registers A = low byte of base address X = unchanged Y = unchanged P = undefined Memory BASL/BASH (address $28-$29) = base address for specified line See also TabV VTab "Standard Output Routines" in Chapter 4 "Text Modes" in Chapter 6 "Display Page Maps" in Chapter 6 APPENDIX F Firmware Entry Points 551 $FC42 ClrEOP Description This routine clears the text window from the cursor position to end of the current line and from the current line to the bottom of the window, and then returns the cursor to its starting position. Input Registers A = any value X = any value Y = any value Memory WNDBTM (address $23) = bottom of window CV (address $25) = vertical position of cursor CH (address 24) = horizontal position of cursor for 40-column screen OURCH (address 057B) = horizontal position of cursor for 80-column screen Output Registers A = undefined X = unchanged Y = undefined P = undefined Memory BASL/BASH (address $28-$29) = base address for current line See also "Standard Output Routines" in Chapter 4 "Text Modes" in Chapter 6 "Display Page Maps" in Chapter 6 552 Apple He Technical Reference $FC58 Home Description This routine moves the cursor to the upper-left corner of the text window and then clears from that position to the bottom of the window. Input Registers A = any value X = any value Y = any value Memory WNDLFT (address $20) = left edge of window WNDWDTH (address $21) = width of window WNDTOP (address $22) = lop of window WNDBTM (address $23) = bottom of window Output Registers A = undefined X = unchanged Y = undefined P = undefined Memory BASL/BASH (address $28-$29) = base address for top line in window See also "'lhe Text Window" in Chapter 4 APPENDIX F Firmware Entry Points 553 $FC62 CR Description This routine executes a carriage return by moving the cursor to the left edge of the window and then calling the LF routine to move the cursor to the next line on the screen. Input Registers A = any value X = any value Y = any value Memory WNDLFf (address $20) = left edge of window Output Registers A = undefined X = unchanged Y = undefined P = undefined See also LF "Standard Output Routines" in Chapter 4 554 Apple He Technical Reference $FC66 LF Description This routine increments the value of CV by 1, moving the cursor down one line. If the new vertical position of the cursor is below the bottom of the window, LF calls the Scroll routine to scroll the window and puts the cursor on the bottom line of the window. LF also calls BasCalc to calculate the starting address in memory (the base address) of the data for the new line on the text screen; BasCalc stores this address in BASL/BASH. Input Registers A = any value X = any value Y = any value Memory WNDBTM (address $23) = bottom of window CV (address $25) = vertical position of cursor Output Registers A = undefined X = unchanged Y = undefined P = undefined Memory CV = previous value of CV + 1 (unless at bottom of window) BASL/BASH (address $28-$29) = base address for new line See also Scroll "Slandard Output Routines" in Chapter 4 "Display Page Maps" in Chapter 6 APPENDIX F Firmware Entry Points 555 $FC70 Scroll Description This routine scrolls the text window by moving all characters in the window up one line. The cursor remains in the same absolute position in the window. Scroll also calls BasCalc to calculate the starting address in memory (the base address) of the data for the new line on the text screen; BasCalc stores this address in BASL/BASH. Input Registers A = any value X = any value Y = any value Memory WNDLFT (address $20) = left edge of window WNDWDTH (address $21) = width of window WNDTOP (address $22) = top of window WNDBTM (address $23) = bottom of window CV (address $25) = vertical position of cursor CH (address $24) = horizontal position of cursor for 40-column screen OURCH (address $057B) = horizontal position of cursor for 80-column screen Output Registers A = undefined X = unchanged Y = undefined P = undefined Memory BASL/BASH (address $28-$29) = base address for new line See also "Standard Output Routines" in Chapter 4 "Display Page Maps" in Chapter 6 556 Apple He Technical Reference $FC9C ClrEOL Description This routine clears a line of text from the cursor position to the right edge of the window. Input Registers A = any value X = any value Y = any value Memory WNDLFT (address $20) = left edge of window WNDWDTH (address $21) = width of window CH (address $24) = horizontal position of cursor for 40-column screen OURCH (address S057B) = horizontal position of cursor for 80-column screen Output Registers A = undefined X = unchanged Y = undefined P = undefined See also ClrEOLZ "Standard Output Routines" in Chapter 4 "Display Page Maps" in Chapter 6 APPENDLX F Firmware Entry Points 557 $FC9E ClrEOLZ Description This routine clears a line of text from the column indicated by the value in the Y register to the right edge of the window. The starting column position is relative to the left edge of the window as stored in WNDLFT; the left edge of the window is column 0. Input Registers A = any value X = any value Y = the horizontal position at which to start clearing text Memory WNDLFT (address $20) = left edge of window WNDWDTH (address $21) = width of window Output Registers A = undefined X = unchanged Y = undefined P = undefined See also OrEOL "Standard Output Routines" in Chapter 4 "Display Page Maps" in Chapter 6 558 Apple He Technical Reference $FCA8 Wait Description This routine causes a pause for an amount of time determined by the value in the A register (accumulator). If the value in the A register is A, then the number of cycles of delay caused by the Wait routine in Apple lie computers is 0.5(26+27A+5A2) To calculate the minimum time delay (in microseconds) caused by the Wait routine in Apple He computers, multiply the number of cycles by 14/14.318181, as follows: 0.488889(26+27A+5A2) microseconds The number of cycles of delay caused by the Wait routine in the Apple He Plus computer is 0.5(50+25A+5A2)+29 Notice that this routine causes A-41 fewer cycles delay than the Wait routine in Apple lie computers. The 65C02 may be running at 4 MHz for up to the first 16 cycles of the Wait routine. The minimum time delay (in microseconds) caused by the Wait routine in the Apple lie Plus computer is therefore 0.977778(0.5(50+25A+5A2)+13) + 0.25(16), or 0.48888960+25A+5A2) +16.711114 microseconds (minimum). A Apple He Plus The Apple lie Plus continues to run at 1.023 MHz for up to 50 msec after exiting from the Wait routine, A Input Registers A = the value used by the routine to determine the duration of the delay X = any value Y = any value APPENDIX F Firmware Entry Points 559 Output Registers A = $00 X = unchanged Y = unchanged P = undefined See also "The Apple He Plus Accelerator RAM" in Chapter 11 560 Apple He Technical Reference $FCB4 NxtA4 Description This routine increments by 1 the 2-byte pointer al A4L/A4H and passes control to NxtAl, which performs a 16-bit comparison of A1L/A1H with A2L/A2H, and then increments A1L/A1H by 1. 'Ihc NxtA4 routine is called repeatedly by the Move and Verify routines as longasAlL/AlH A2L/A2H Memory A4L/A4H = previous value of A4L/A4H + 1 A1L/A1H = previous value of A1L/A1H + 1 See also NxtAl Move APPENDLX F Firmware Entry Points 56l $FCBA NxtAl Description This routine performs a 16-bit comparison of A1L/A1H with A2L/A2H, and then increments A1L/A1H by 1. NxtAl is an alternate entry point to the NxtA4 routine; NxtAl does not increment A4L/A4H, but is otherwise identical to NxiA4. Input Registers A = any value X = any value Y = any value Memory A1L/A1H (addresses $3C-$3D) = pointer to be incremented A2L/A2H (addresses $3E-$3F) = pointer compared with A1L/A1H Output Registers A = undefined X = unchanged Y - unchanged P - changed; C flag is set if A1L/A1H > A2I/A2H Memory A1L/A1H = previous value of A1L/A1H + 1 See also NxtA4 Move 562 Apple He Technical Reference $FCC9 HeadR Description This address is an obsolete entry point. It does nothing except return to the calling routine with an RTS instruction. Input Registers A = any value X = any value Y = any value Output Registers A = unchanged X • unchanged Y • unchanged P = unchanged APPENDIX F Firmware Entry Points 563 $FDOC RdKey Description This routine loads the A register (accumulator) with the character at the current cursor position and passes control to the FD10 routine, which jumps to an input routine. Input Registers A = any value X = any value Y = any value Memory CH (address $24) = horizontal position of cursor BASL/BASH (address $28-529) = base address of current line Output Registers A = character at current cursor position X = unchanged Y = value in CH P = undefined See also FD10 "RdKey Subroutine" in Chapter 4 564 Apple lie Technical Reference $FD10 FD10 Description This routine jumps to the routine whose address is stored in KSWL/KSWH, usually the routine Keyln (when the enhanced video firmware is not active) or C3KeyIn (when the enhanced video firmware is active). The FD10 address is maintained as an alternative entry point for the KcylnO routine; there is no functional difference between these routines. Input Registers A = any value X = any value Y = any value Memory KSWL/KSWH (address $38-$39) = address to which to jump Output This routine jumps to the routine pointed to by KSWL/KSWH; it does not return to the calling routine. See also RdKey Keyln "The Standard I/O Links" in Chapter 4 APPENDIX F Firmware Entry Points 565 $FD18 KeylnO Description This routine jumps to the routine whose address is stored in KSWL/KSWH, usually the routine Keyln (when the enhanced video firmware is not active) or C3Keyln (when the enhanced video firmware is active). Input Registers A = any value X = any value Y = any value Memory KSWL/KSWH (address $38-$39) = address to which to jump Output This routine jumps to the routine pointed to by KSWL/KSWH; it does not return to the calling routine. See also RdKey Keyln "The Standard I/O Links" in Chapter 4 566 Apple lie Technical Reference $FD1B Keyln Description This routine displays a cursor, waits until a key is pressed, then loads the ASCII code for that key into the A register (accumulator), removes the cursor from the display, and returns to the calling program. If Escape mode is set when you call Keyln, and the user presses the Esc key, then Keyln processes the Escape sequence. Use the RdChar routine to call Keyln with Escape mode set. The cursor displayed by the Keyln routine is determined by the value stored in CURSOR. If CURSOR = $00, the block cursor normally used by the enhanced video firmware is displayed. If CURSOR = $FF, the checkerboard cursor normally used when the enhanced video firmware is inactive is displayed. If CURSOR is any other value, the inverse of the character represented by that value is displayed. While the Keyln routine is waiting for a keypress, it continuously updates RNDL/RNDH, which you can use as a seed for a random-number generator. The C3KeyIn routine, normally called by RdKey when the enhanced video firmware is active, first calls the COutZ routine to display the solid-block cursor on the screen, and then calls the Keyln routine. Input Registers A = character at the cursor position X = any value Y = any value Memory CURSOR (address S07FB) = type of cursor to display APPENDIX F Firmware Entry Points 567 Output Registers A = key pressed X = unchanged Y = undefined P = undefined Memory RNDL/RNDH (addresses $4E-$4F) - random number See also RdKey RdChar "The Keyln and C3KeyIn Input Routines" in Chapter 4 568 Apple lie Technical Reference $FD35 RdChar Description This routine sets escape mode to active and then jumps to the RdKey routine. Escape mode is shown in Table F-4. Table F-4 Escape sequences with RdChar Escape code Function Esc Clears the window and homes the cursor (places it in the upper-left corner of the screen); exits from escape mode Esc A or Esc a Moves the cursor right one line; exits from escape mode Esc B or Esc b Moves the cursor left one line; exits from escape mode Esc C or Esc c Moves the cursor down one line; exits from escape mode Esc D or Esc d Moves the cursor up one line; exits from escape mode Esc E or Esc e Clears to the end of the line; exits from escape mode Esc F or Esc f Clears to the bottom of the window; exits from escape mode Esc 1 or Esc i or Esc Up Arrow Moves the cursor up one line; remains in escape mode Esc J or Escj or Esc Left Arrow Moves the cursor left one space; remains in escape mode Esc K or Esc k or Esc Right Arrow Moves the cursor right one space; remains in escape mode Esc M or Esc m or Esc Down Arrow Moves the cursor down one line; remains in escape mode Esc 4 Switches to 40-column mode; sets links to C3KeyIn and C3COutl; restores normal window size (Table 4-5); exits from escape mode* Esc 8 Switches to 80-column mode; sets links to C3KeyIn and C3COutl; restores normal window size (Table 4-5); exits from escape mode' Esc Control-D Disables control characters; only carriage return, linefeed, bell, and backspace have an effect when printed Esc Control-E Reactivates control characters Esc Control-Q Deactivates the enhanced video firmware; sets links to Keyln and COutl; restores normal window size (Table 4-5); exits from escape mode' * This code functions only when the enhanced video firmware is active. APPENDIX F Firmware Entry Points 569 Input Registers A = any value X = any value Y = any value Memory CH (address $24) = horizontal position of cursor BASL/BASH (address $28-$29) = base address of current line Output Registers A = character at current cursor position X = unchanged Y = value in CH P = undefined See also RdKey "RdKey Subroutine" in Chapter 4 570 Apple lie Technical Reference $FD67 GetLnZ Description This routine sends a carriage return to standard output and then passes control to the GetLn routine. The GetLn routine displays the prompt character stored in PROMPT and calls RdKey repeatedly—with escape mode set—to read an entire line of characters from standard input. If the user presses Control-X or backspaces to the first column in the window, GetLn ignores the characters on the line and returns control to GetLnZ. Input Registers A = any value X = any value Y = any value Memory CH (address $24) = horizontal position of cursor BASL/BASH (address $28-$29) = base address of current line PROMPT (address $33) = the ASCII code (high bit set) of the character to be used as a prompt Output Registers A = undefined X = length of input line Y = undefined P = undefined Memory 1NBUF (address $0200-$02xx) = input line See also GetLn RdKey RdChar "GetLn Subroutine" in Chapter 4 APPENDIX F Firmware Entry Points 571 $FD6A GetLn Description This routine displays the prompt character stored in PROMPT and calls RdKey repeatedly— with escape mode set—to read an entire line of characters from standard input. Each character is placed in the input buffer (at $0200) at a relative offset equal to the character's position on the line. If the user presses the Left Arrow key (Control-H, $88), GetLn moves the cursor left one space, leaves the character on the screen, and places in the input buffer a backspace character ($88) corresponding to the cursor's new position. If the user presses Control-X or backspaces to the first column in the window, GetLn ignores all the characters on the line and jumps to GetLnZ, which executes a carriage return and passes control to GetLn. (If the user presses Control-X, GetLn prints a backslash before jumping to GetLnZ.) If the user presses the Right Arrow key (Control-U, $95), GetLn reads the character that the cursor was on, and stores it in the input buffer instead of storing $95. For example, suppose you are in the Monitor (which uses GetLn for input) and type the following characters: 300LXY / E Carriage Return The input buffer would then contain the following data: $B3$BO$B0$CC$8D$88 This corresponds to the following string: 30 0L Carriage Return" Input Registers A = any value X = any value Y = any value 572 Apple He Technical Reference Memory CH (address $24) = horizontal position of cursor BASL/BASH (address $28-S29) = base address of current line PROMPT (address $33) = the ASCII code (high bit set) of the character to be used as a prompt if control is passed to GetLnZ Output Registers A = undefined X = length of input line Y = undefined P = undefined Memory INBUF (address $0200-$02xx) • input line See also RdKey RdChar "GetLn Subroutine" in Chapter 4 r APPENDIX F Firmware Entry Points 573 $FD6C GetLnO Description This routine displays as a prompt the character stored in the A register (accumulator), and calls RdKey repeatedly—with escape mode set—to read an entire line of characters from standard input. GetLnO is an alternate entry point to the GetLn routine. If the user presses Control-X or backspaces to the first column in the window, Gelin ignores the characters on the line and jumps to GetLnZ. Input Registers A = any value X = any value Y = any value Memory CH (address $24) = horizontal position of cursor BASL/BASH (address $28-$29) = base address of current line PROMPT (address $33) = the ASCII code (high bit set) of the character to be used as a prompt if control is passed to GetLnZ Output Registers A = undefined X = length of input line Y = undefined P = undefined Memory INBUF (address $0200-$02xx) = input line See also GetLn RdKey RdChar "GetLn Subroutine" in Chapter 4 574 Apple lie Technical Reference $FD6F GetLnl Description This routine calls RdKey repeatedly—with escape mode set—to read an entire line of characters from standard input. GetLnl is an alternate entry point to the GetLn routine that does not display a prompt character. If the user presses Control-X or backspaces to the first column in the window, GetLn ignores the characters on the line and jumps to GetLnZ. Input Registers A = any value X = any value Y = any value Memory CH (address $24) = horizontal position of cursor BASL/BASH (address $28-$29) = base address of current line PROMPT (address $33) = the ASCII code (high bit set) of the character to be used as a prompt if control is passed to GetLnZ Output Registers A = undefined X = length of input line Y = undefined P = undefined Memory INBUF (address $0200-$02xx) = input line See also GetLn RdKey RdChar "GetLn Subroutine" in Chapter 4 APPENDIX F Firmware Entry Points 575 $FD8B CROutl Description This routine clears the current line from the current cursor position to the right edge of the text window, then passes control to CROut, which sends a carriage return to standard output. Input Registers A = any value X = any value Y = any value Output Registers A = carriage return character X = unchanged Y = undefined P = undefined See also CROut COut 5 76 Apple He Technical Reference $FD8E CROut Description This routine sends a carriage return to standard output. Input Registers A = any value X = any value Y = any value Output Registers A = carriage return character ($8D) X = unchanged Y = undefined P = undefined See also CROut COut APPENDIX F Firmware Entry Points 577 $FD92 PrAl Description This routine sends a carriage return to standard output, then prints to standard output the contents of A1L/A1H in hexadecimal, followed by a hyphen (-). The Verify routine uses the PrAl routine followed by the PrByte routine to print an address followed by the value in that address during a comparison of memory ranges. Input Registers A • any value X = any value Y = anv value Memory A1L/A1H (addresses $3C-$3D) = values printed out by this routine Output Registers A = $AD (hyphen) X = undefined Y = $00 P = undefined See also PrByte COut Verify "Running a Program" in Chapter 10 578 Apple lie Technical Reference $FDDA PrByte Description This routine prints to standard output the contents of the A r hexadecimal format. Input Registers A = value to be printed as a hexadecimal number X = any value Y = any value Output Registers A = undefined X = unchanged Y = unchanged P = undefined See also PrHex COut APPENDIX F Firmware Entry Points 579 $FDE3 PrHex Description This routine prints to standard output the lower nibble of the contents of the A register (accumulator) in hexadecimal format. Input Registers A = value, lower nibble of which is to be printed as a hexadecimal number X = any value Y = any value Output Registers A • undefined X = unchanged Y = unchanged P = undefined See also PrByte COut 580 Apple He Technical Reference $FDED COut Description This routine calls the text output routine whose address is stored in CSWL/CSWH. When the enhanced video firmware is not active, COut normally calls COutl; when the enhanced video firmware is active, COut normally calls C3COutl. Input Registers A = character to be printed X = any value Y = any value Memory CSWL/CSWH (addresses $36-$37) = address of output routine to which COut passes control Output Registers A = unchanged X = unchanged Y = unchanged P = undefined See also COutl CoutZ "The Standard I/O Links" in Chapter 4 APPENDIX F Firmware Entry Points 581 $FDFO COutl Description This routine displays the character in the A register (accumulator) on the screen at the current cursor position and advances the cursor. COutl also handles the following control characters: carriage return ($8D); line feed (Down Arrow, $8C), backspace (Left Arrow, $88); and bell (Control-G, $87). The character displayed depends on the value of the inverse flag INVFLG; COutl applies the inverse flag unless the character is a control character. See the sections "Primary Character Set Display" and "Alternate Character Set Display" in Chapter 4 for a discussion of the inverse flag. The C3COull routine, normally called by COut when the enhanced video firmware is active, calls the COutZ entry point to the COutl routine. The enhanced video firmware includes routines to handle a variety of control characters that are ignored when the enhanced video firmware is not active; see the section "Control Characters Wilh C3Coutl" in Chapter 4 for details. Input Registers A = character to be printed X = any value Y = any value Memory CV (address $25) = vertical position of cursor CH (address $24) = horizontal position of cursor for 40-column screen INVFLAG (address $32) = inverse flag OURCH (address S057B) = horizontal position of cursor for 80-column screen Output Registers A = unchanged X = unchanged Y = unchanged P = undefined See also COut COutZ "Standard Output Routines" in Chapter 4 582 Apple lie Technical Reference $FDF6 COutZ Description This address is an alternate entry point to the COutl routine. The COutZ routine is identical to the COutl routine, except that the inverse flag is not applied to the character at the beginning of the routine. The enhanced video firmware, which applies the inverse flag after checking for and handling control characters, uses the COutZ entry point to avoid applying the inverse flag twice. Input Registers A = character to be printed X • any value Y = any value Memory CV (address $25) = vertical position of cursor CH (address $24) = horizontal position of cursor for 40-column screen INVFLAG (address $32) = inverse flag OURCH (address $057B) = horizontal position of cursor for 80-column screen Output Registers A = unchanged X • unchanged Y = unchanged P = undefined See also COut COutl "Standard Output Routines" in Chapter 4 APPENDIX F Firmware Entry Points 583 $FE1F IDRoutine Description This routine, when called with the c flag set, returns with the c flag still set. If the c flag were returned clear, that would indicate that the machine is an Apple IIGS or later system, and the A, X, and Y registers would contain identification information. Input Registers A = any value X = any value Y = any value P = any value, except that c flag must be set Output Registers A = unchanged X = unchanged Y = unchanged P • unchanged 584 Apple He Technical Reference $FE2C Move Description This routine copies the contents of memory from one range of locations into another range of locations. The Move routine reads the contents of memory pointed to by the address in A1L/A1H, plus any offset in the Y register; the instruction is LDA ( A I L > , Y . Then the routine stores the data in the location pointed to by A4L/A4H; the instruction is STA (A4 L) , Y . The address of the end of the source buffer is stored in A2L/A2H. The Move routine calls the NxtA4 routine. The NxtA4 routine increments A4L/A4H and A1L/A1H and compares A1L/A1H to A2L/A2H, then returns to the Move routine with an RTS instruction. If A1L/A1H < A2L/A2H (the c flag is clear), the Move routine loops back to the Move entry point; if A1L/A1H > A2L/A2H, the Move routine exits with an RTS instruction. Input Registers A = any value X = any value Y = initial offset into source and destination buffers; normally $00 Memory AlL/AlFi (addresses $3C-$3D) = pointer to start of source buffer A2L/A2H (addresses $3E-$3F) = pointer to end of source buffer A4L/A4H (addresses S42-$43) = pointer to start of destination buffer Output Registers A = undefined X = unchanged Y = unchanged P = undefined Memory Al L/Al H = pointer to end of source buffer + 1 A2L/A2H = pointer to end of source buffer A4L/A4H = pointer to end of destination buffer + 1 See also "Moving Data in Memory" in Chapter 10 APPENDIX F Firmware Entry Points 585 $FE36 Verify Description This routine compares the contents of two ranges of memory. The Verify routine reads the contents of memory pointed to by the address in AIL /A1H, plus any offset in the Y register; the instruction is LDA (AIL) , Y . Then Lhe routine reads the data in lhe location pointed to by A4L/A4H; the instruction is CMP (A4L) , Y. The final address to be compared is stored in A2L/A2H. If the contents of one address in the first block of data do not match those of the corresponding address in the second block of data, Verify prints out the first address, a hyphen (-), the contents of the address in the first block, and (in parentheses) the contents of the address in the second block. For example, if you call Verify with $O3OO-$03OF in A1L/A1H-A2IVA2H and $0350 in A4L/A4H, and if the value in $0305 is $1F while the value in $0355 is $AE, Verify prints out the following line: 0305-1F (AE) Input Registers A = any value X = any value Y = initial offset into blocks of data; normally = $00 Memory A1L/A1H (addresses $3C-$3D) = pointer to start of first block of data A2L/A2H (addresses $3E-$3F) = pointer to end of first block of data A4L/A4H (addresses $42-543) = pointer to start of second block of data Output Registers A = undefined X = unchanged Y = unchanged P = undefined Memory A1L/A1H = pointer to end of first block of data + 1 A2L/A2H = pointer to end of first block of data A4L/A4H = pointer to end of second block of data + 1 See also "Comparing Data in Memory" in Chapter 10 586 Apple He Technical Reference $FE5E List Description This routine disassembles 20 instructions, starting at the address in A1L/A1H, and prints them to standard output. Input Registers A = any value X = $01 Y = any value Memory A1L/A1H (addresses $3C-$3D) = pointer to first address to disassemble Output Registers A = undefined X = undefined Y = undefined P = undefined See also "Disassembled Programs" in Chapter 10 APPENDIX F Firmware Entry Points 587 $FE80 Setlnv Description This routine sets INVFLG to $3F so that subsequent text that is output through COutl will he displayed as inverse characters. Input Registers A = any value X = any value Y = any value Output Registers A = unchanged X = unchanged Y = undefined P = undefined Memory INVFLG (address $32) = $3F See also COutl SetNorm "Normal, Inverse, and Flashing Text" in Chapter 4 588 Apple lie Technical Reference $FE84 SetNorm Description This routine sets INVFLG to $FF so that subsequent text that is output through COutl will be displayed as normal characters. Input Registers A = any value X = any value Y = any value Output Registers A = unchanged X = unchanged Y = undefined P = undefined Memory INVFLG (address $32) = $FF See also COutl Setlnv "Normal, Inverse, and Flashing Text" in Chapter 4 APPENDIX F Firmware Entry Points 589 $FE89 SetKbd Description This routine sets the input li: Keyln. Input Registers A = any value X = any value Y = any value Output Registers A = undefined X = undefined Y = undefined P = undefined Memory KSWI7KSWH (addresses $38-$39) • Keyln ($FD1B) See also Keyln In Port The Standard I/O Links" in Chapter 4 590 Apple He Technical Reference $FE8B InPort Description This routine sets the input links KSWL/KSWH to point to the ROM code for the port whose number is in the A register (accumulator). The next attempt to get input through the standard input links will then execute the ROM code that starts al the entry point for the specified port. Setting the A register to $00 and calling InPort is equivalent to calling the SetKbd routine. Input Registers A = number of port ($00-$07) X = any value Y = any value Output Registers A = undefined X = undefined Y = undefined P = undefined Memory KSWL/KSWH (addresses $38-539) = $Cn00, where n is the number in the A register See also SetKbd "The Standard I/O Links" in Chapter 4 "Standard Link Entry Points" in Chapter 4 APPENDIX F Firmware Entry Points 591 $FE93 SetVid Description This routine sets the output links CSWL'CSWH to point to the screen display routine COutl. Input Registers A = any value X = any value Y = any value Output Registers A = undefined X = undefined Y = undefined P = undefined Memory CSWL/CSWH (addresses $36-$37) = COutl ($FDF0) See also COutl OutPort "The Standard I/O Links" in Chapter 4 592 Apple He Technical Reference $FE95 OutPort Description This routine sets the output hooks CSWL/CSWH to point to the ROM code for the port whose number is in the A register (accumulator). The next attempt to send output through the standard output hooks will then execute the ROM code that starts at the entry point for the specified port. Setting the A register to $00 and calling OutPort is equivalent to calling the SelVid routine. Input Registers A = number of port ($00-$07) X = any value Y = any value Output Registers A = undefined X = undefined Y = undefined P = undefined Memory CSWL/CSWH (addresses $36-$37) = $CnOO, where n is the number in the A register See also SetVid "The Standard I/O Links" in Chapter 4 "Standard Link Entry Points" in Chapter 4 APPENDLX F Firmware Entry Points 593 $FEB6 GO Description This routine sets the A, X, Y, and P registers to the values stored in A5H, XREG, YREG, and STATUS, then jumps to the address stored in A1L/A1H. Input Registers A = any value X = $01 Y = any value Memory A1L/A1H (addresses $3C-$3D) = the starling address of the routine to be executed A5H (address $45) = the value to which the A register is set XREG (address $46) = the value lo which the X register is set YREG (address $47) = the value to which the Y register is set STATUS (address $48) = the value to which lhe P register is set Output Registers A = undefined X = undefined Y = undefined P = undefined See also "Running a Program" in Chapter 10 594 Apple lie Technical Reference $FECD Write Description This address is an obsolete entry point. It does nothing except return to Lhe calling routine wilh an RTS instruction. Input Registers A = any value X = any value Y = any value Output Registers A = unchanged X = unchanged Y = unchanged P = unchanged APPENDIX F Firmware Entry Points 595 $FEFD Read Description This address is an obsolete entry point. It does nothing except reLurn to the calling routine with an RTS instruction. Input Registers A = any value X = any value Y = any value Output Registers A = unchanged X = unchanged Y = unchanged P = unchanged 596 Apple lie Technical Reference $FF2D PrErr Description This routine prints the letters ERR to standard output and sends a bell character ($87) to standard output. Input Registers A = any value X = any value Y = any value Output Registers A = $87 (bell character) X = unchanged Y = unchanged P = undefined APPENDLX F Firmware Entry Points 597 $FF3A Bell Description This routine sends a bell character ($87) to standard output. Input Registers A = any value X = any value Y = any value Output Registers A = $87 (bell character) X = unchanged Y = unchanged P • undefined See also Belli Belll.2 Bell2 598 Apple He Technical Reference $FF3F Restore Description This routine sets the A, X, Y, and P registers to the values stored in A5H, XREG, YREG, and STATUS. Input Registers A = any value X = any value Y = any value Memory A5H (address $45) = the value to which the A register is to be set XREG (address $46) = the value to which the X register is to be set YREG (address $47) = the value to which the Y register is to be set STATUS (address $48) = the value to which the P register is to be set Output Registers A = the value in A5H X = the value in XREG Y = the value in YREG P = the value in STATUS See also Save "Monitor Register Commands" in Chapter 10 APPENDIX F Firmware Entry Points 599 $FF4A Save Description This routine stores the contents of the A, X, Y, P, and S registers in A5H, XREG, YREG, STATUS, and SPNT. At the end of the routine, Save clears the 65C02 processor's decimal mode flag. Input Registers A = any value X = any value Y = any value Output Registers A = undefined X = undefined Y = unchanged P = changed; decimal mode flag cleared Memory A5H (address $45) = the value in the A register when Save was called XREG (address $46) = the value in the X register when Save was called YREG (address $47) = the value in the Y register when Save was called STATUS (address $48) = the value in the P register when Save was called SPNT (address ($49) = 2 less than the value in the S register when Save was called See also Restore "Monitor Register Commands" in Chapter 10 600 Apple He Technical Reference $FF58 IORTS Description This address contains an RTS instruction. In Apple II machines with expansion slots, a peripheral card can use this RTS instruction to determine which slot it is in. Input Registers A = any value X = any value Y = any value Output Registers A = unchanged X = unchanged Y = unchanged P = unchanged APPENDIX F Firmware Entry Points 601 $FF59 OldRst Description This rouline sets the text display to normal characters, initializes the lext screen, sets the output hooks CSWL/CSWH to point to the screen display routine, COutl, and sets the input hooks KSWL/KSWH to point to the keyboard input rouline, Keyln. The OldRst routine then passes control to Mon, which clears the 65C02 processor's decimal mode flag, sounds the speaker, and enters the Monitor. Input Registers A = any value X = any value Y = any value Output The OldRst routine does not reLurn to the calling program. Memory INVFLG (address $32) = $FF BASL/BASH (address $28-$29) = base address of last line in window CSWL/CSWH (addresses $36-$37) = COutl ($FDF0) KSWL/KSWH (addresses $38-$39) = Keyln ($FD1B) See also SetNorm Init SetVid SetKbd Mon 602 Apple lie Technical Reference $FF65 Mon Description This routine clears the 65C02 processor's decimal mode flag, sounds the speaker, and enters the Monitor at MonZ. Input Registers A = any value X = any value Y = any value Output The Mon routine does not return to the calling program. See also OldRst MonZ APPENDIX F Firmware Entry Points 603 $FF69 MonZ Description This address is the entry point for the System Monitor to which control is passed when you execute the CALL -151 command from Applesoft. The MonZ routine calls the GetLnZ routine to display the Monitor's asterisk (') prompt and read a line of lext, calls ZMode to clear the Monitor mode, and passes control lo the Monitor's command-line parser. Input Registers A = any value X = any value Y = any value Output The MonZ rouline does not return to 1 See also GelLnZ OldRst Mon ZMode "Invoking the Monitor" in Chapter 10 604 Apple lie Technical Reference $FF70 MonZ4 Description This address is an alternate eniry point to the System Monitor. It is the same as the MonZ routine, except that it does not call GetLnZ or ZMode. Your program must read a line of text and clear the Monitor mode before calling MonZ4. Input Registers A = any value X = any value Y = any value Output The MonZ4 routine does not return to the calling program. See also GetLnZ MonZ ZMode "Invoking the Monitor" in Chapter 10 APPENDIX F Firmware Entry Points 605 $FF8A Dig Description This routine converts an ASCII code for a hexadecimal digit in the Monitor's input buffer into the appropriate hexadecimal number and stores thai number in A2L/A2H. Dig is called by NxtChr, which performs an exclusive OR operation on each ASCII code wilh $B0 before passing it to Dig in the A register (accumulator). If lhe character is from $A to $F, NxtChr also adds $88 lo the result of the EOR operation and seLs the carry flag before calling Dig. Dig shifts the character bit-by-bit into A2L/A2H in memory. This combination of the NxtChr routine and the Dig routine converts the ASCII representation of a digit into the correct number in memory; for example, the ASCII code $B3 ends up in A2L/A2H as $00 $03. Dig then passes control back to NxtChr. Input Registers A = ASCII code after conditioning by NxlChr rouline X = any value Y = offset into input buffer for next character to decode Memory $0200 = start of input buffer Output Registers A = undefined X = undefined Y = offset into input buffer for next character to decode P = undefined Memory A2L/A2H (addresses $3E-$3F) = hexadecimal number decoded from ASCII character in input buffer See also NxtChr 606 Apple He Technical Reference $FFA7 GetNum Description This routine scans the Monitor's input buffer starting at the offset in the Y register. It decodes ASCII codes for hexadecimal numbers into their corresponding hexadecimal values and stores them in A2L/A2H until it encounters an ASCII code that doesn't correspond to a hexadecimal number. GetNum uses NxtChr to test, parse, and decode the hexadecimal numbers. Input Registers A = any value X = any value Y = offset into input buffer for first character to decode Memory $0200 = start of input buffer Output Registers A = undefined X = undefined Y = offset into input buffer for next character to decode P = undefined Memory A2L/A2H (addresses $3E-$3F) = hexadecimal number decoded from ASCII character in input buffer See also NxtChr APPENDIX F Firmware Entry Points 607 $FFAD NxtChr Description This routine tests each character in the input buffer to see if it is an ASCII code for a hexadecimal number. If the code is for a hexadecimal number, NxtChr calls Dig to decode lhe ASCII value into its corresponding hexadecimal number and stores the number in A2L/A2H. NxtChr also converts any lowercase ASCII values into their uppercase equivalents. Input Registers A = any value X = any value Y = offset into input buffer for first character to decode Memory $0200 = start of input buffer Output Registers A = undefined X = undefined Y = offset into input buffer for next character to decode P = undefined Memory A2L/A2H (addresses $3E-$3F) = hexadecimal number decoded from ASCII character in input buffer See also GetNum Dig 608 Apple lie Technical Reference $FFC7 ZMode Description This routine stores $00 in the Monitor's Mode byte to clear the Monitor mode. The Mode byte is used by the Monitor to determine how to handle hexadecimal numbers that are included in the input line, as shown in Table F-5. Table F-5 Monitor modes MODE Meaning Command-line symbol $AB Addition mode $AD Subtraction mode $A£ Memory display (examine) mode $BA Memory fill (data store) mode Input Registers A = any value X = any value Y = any value Output Registers A = unchanged X = unchanged Y = $00 P = undefined Memory MODE (address $31) = $00 See also ToSub "Monitor Memory Commands" in Chapter 10 "Hexadecimal Arithmetic" in Chapter 10 APPENDIX F Firmware Entry Points 609 Appendix G Conversion Tables This appendix briefly discusses bits and bytes and what they can represent, and then discusses peripheral identification numbers. It also contains conversion tables for hexadecimal to decimal and negative decimal, and a number of 8-bit codes. These tables are intended for convenient reference. This appendix is not intended as a tutorial for the materials discussed. The brief section introduclions are for orientation only. • 611 Bits and bytes This section discusses the relationships between bit values and their position within a byte. Here are some rules of thumb regarding the 65C02: • A bit is a binary digit; it can be either a 0 or a 1. • A bit can be used to represent any two-way choice. Some choices that a bit can represent in the Apple Ilc-family computers are listed in Table G-l. • Bits can also be combined in groups of any size to represent numbers. Most of lhe commonly used sizes are multiples of 4 bits. • Four bits make a nibble (sometimes spelled nybble). • One nibble can represent any of 16 values. Each of these values is assigned a number from 0 through 9 and (because our decimal system has only 10 of the 16 digits we need) A through F. • Eight bits (two nibbles) make a byte (see Figure G-l). • One byte can represent any of 16 x 16 (or 256) values. The value can be specified by exactly two hexadecimal digits. • Bits within a byte are numbered from bit 0 on the right lo bit 7 on the left. • The bit number is the same as the power of 2 that it represents, in a manner completely analogous to the digits in a decimal number. • One memory position in the Apple Ilc-family computers contains one 8-bit byte of data. • How byte values are interpreted depends on whether the byte is an instruction in a language, part or all of an address, an ASCII code, or some other form of data. Tables G-6 through G-9 list some of the ways bytes are commonly interpreted. • Two bytes make a word. The 16 bits of a word can represent any one of 256 x 256 (or 65,536) different values. • The 65C02 uses a 16-bit word to represent memory locations. It can therefore distinguish among 65,536 (64 KB) locations at any given time. • A memory location is one byte of a 256-byte page. The low-order byte of an address specifies this byte. The high-order byte specifies the memory page the byte is on. 612 Apple lie Technical Reference Table G-l What a bit can represent Context Representing 0- Binary number Place value 0 1 x thai power of 2 Logic Condition False True Any switch Position Off On Any switch Position Clear* Set Serial transfer Beginning Start Carrier (no information yet) Serial transfer Data 0 value 1 value Serial transfer Parity SPACE MARK Serial transfer End Stop bit(s) Serial transfer Communication BREAK Carrier state P reg. bit n Neg. resulL' No Yes P reg. bit v Overflow? No Yes P reg. bit b BRK command? No Yes P reg. bit d Decimal mode? No Yes P reg. bit i IRQ interrupts Enabled Disabled (masked out) P reg. bit z Zero result' No Yes P reg. bit c Carry required? No Yes ' Sometimes ambiguously termed reset. Figure G-l Bits, nibbles, and bytes High Nibble Low Nibble f * v- ^ MSB LSB 7 6 5 4 3 2 1 0 Hexadecimal $80 $40 $20 $10 $08 $04 $02 $01 Decimal 128 64 32 16 8 4 2 1 APPENDIX G Conversion Tables 613 Table G-2 Values represented by a nibble Binary Hex Dec Binary Hex Dec 0000 $0 0 1000 $8 8 0001 $1 1 1001 $9 9 0010 $2 2 1010 $A 10 0011 $3 3 1011 $B 11 0100 $4 4 1100 $C 12 0101 $5 5 1101 $D 13 0110 $6 6 1110 SE 14 0111 $7 7 mi $F 15 Hexadecimal and decimal Use Table G-3 for conversion of hexadecimal and decimal numbers. • Table G-3 Hexadecimal/decimal conversion Digit SxOOO $0x00 $00x0 $000x F 61440 3840 240 15 E 57344 3584 224 14 D 53248 3328 208 13 C 49152 3072 192 12 B 45056 2816 176 11 A 40960 2560 160 10 9 36864 2304 144 9 8 32768 2048 128 8 7 28672 1792 112 7 b 24576 1536 96 6 5 20480 1280 80 5 4 16384 1024 64 4 3 12288 768 48 3 2 8192 512 32 2 1 4096 256 16 1 614 Apple lie Technical Reference To convert a hexadecimal number to a decimal number, find the decimal numbers corresponding to the positions of each hexadecimal digit. Write ihcm down and add them up. For example: $3C = ? $ FD47 = ? $30 = 4 8 $ F000 = 61440 SOC = 12 $ D00 = 3328 $3C = 6 0 S 40 = 64 S 7 = 7 $ FD47 = 64839 To convert a decimal number lo hexadecimal, subtract from the decimal number the largest decimal entry in the table that is less than it. Write down the hexadecimal digit (noting its place value) also. Now subtract the largest decimal number in the table that is less than the decimal remainder, and write down the next hexadecimal digit. Continue until you have a remainder less than 16, Add up the hexadecimal numbers. For example: 16215 5 ? 16215 -12288 = 3927 12288 = $ 3000 3927 - 3840 = 87 3840 = $ F00 87 - 80 - 7 80 = $ 50 7 7 = $ 7 16215 = $ 7F57 Hexadecimal and negative decimal If a number is larger than decimal 32,767, Applesoft BASIC allows and Integer BASIC requires you to use the negative decimal equivalent of the number. Table G-4 is set up to make it easy for you to convert a hexadecimal number directly to a negative decimal number. APPENDIX G Conversion Tables 615 Table G-4 Hexadecimal to negative decimal conversion Digit $x000 $0x00 $00x0 $000x F 0 0 0 -1 E -1096 -256 -16 -2 D -8192 -512 -32 -3 C -12288 -768 -18 -i B -16384 -1024 -64 -5 A -20480 -1280 -80 -6 9 -24576 -1536 -96 -7 8 -28672 -1792 -112 -8 7 -2048 -128 -9 6 -2304 -144 -10 5 -2560 -160 -11 4 -2816 -176 -12 3 -3072 -192 -13 2 -3328 -208 -14 1 -3584 -224 -15 0 -3840 -240 -16 To perform this conversion, write down the four decimal numbers corresponding to the four hexadecimal digits (0's included). Then add their values (ignoring their signs for a moment). The resulting number, with a minus sign in front of it, is the desired negative decimal number. For example: $C010 = ? $C000 =-12288 $ 000 = -3840 $ 10 = -224 $ 0 -16 $C010 =-16368 6l6 Apple lie Technical Reference To convert a negative decimal number directly to a positive decimal number, add it to 65,536. (This addition ends up looking like subtraction.) For example: -151 = + ? 65536 + (-151) = 65536-151 = 65385 To convert a negative decimal number lo a hexadecimal number, first convert il to a positive decimal number, then use Table G-3. Peripheral identification numbers Many Apple products now use peripheral identification numbers (called PINs) as shorthand to designate serial device characteristics. The Apple II-series Universal Utilities disk presents a menu from which to select the characteristics of, say, a printer or modem. From the selections made, it generates a PIN for the user. Other products have a ready-made PIN that the user can simply type in. Table G-5 is a definition of lhe PIN digits. When communication mode is selected, the seventh digit is ignored. For example, a PIN of 252/111 means that a device operates with the following characteristics: Communications mode; 8 data bits, 1 stop bit; 300 baud/no parity; no echo of output lo display; no LF after CR; no CRs generated APPENDDCG Conversion Tables 617 Table G-5 PIN digits 1 = Printer mode 2 = Communication mode* u- 1 • 6 data bits, 1 stop bit 2 = 6 data bits, 2 stop bits 3 - 7 data bits, 1 stop bit 4 - 7 data bits, 2 stop bits 5 - 8 data bits, 1 stop bit 6 - 8 data bits, 2 stop bits 1-110 bits per second 2-300 bits per second 3 - 1200 bits per second 4 - 2400 bits per second 5 = 4800 bits per second 6 - 9600 bits per second 7 -19200 bits per second 1 = No parity 26 •- Even u v t u parity yamy (total vuuuu on u u -- even) tvciiy 3 - Odd parity (total on » odd) 4 - MARK parity (parity bit - 1) 5 - SPACE parity (parity I 1 = Do not echo output on screen —1 2 • Echo output on screen —•" 1 • Do not generate LF after CR 2 - Generate LF after CR IF 1 - Do not generate CR' 2 = Generate CR after 40 characters 3 - Generate CR after 72 characters 4 - Generate CR after 80 characters 5 - Generate CR after 132 characters ' I/you select communication mode, then the seventh digit must equal 1. This value is supplied automatically when you use the UUD. 618 Apple lie Technical Reference Apple He-family character set Tables G-6 through G-9 show the entire ASCII character set. Note that character values are shown with the high bit off. Unless olherwise noted, all ASCII character values above $7F (127 decimal) generate the same character as that value with the high bit off. Here is how to interpret these tables: • The Binary column has the 8-bit code for each ASCII character. • The first 128 ASCII entries represent 7-bit ASCII codes plus a high-order bit of 0—for example, 01001000 for the letter H. • A transmitted or received ASCII character will lake whichever form (in the communication register) is appropriate if odd or even parity is selected—for example, 11001000 for an odd-parity H, 01001000 for an even-parity H. • The ASCII cliar column gives the ASCII character name. • The Interpretation column spells out the meaning of special symbols and abbreviations, where necessary. • The What to type column indicates what keystrokes generate the ASCII character (where it is not obvious). • The columns marked Pri and Alt indicate what displayed character results from each code when using the primary or alternate display character set, respectively. Boldface is used for inverse characters; italic is used for flashing characters. Note that the values $40 through $5F (and $C0 through $DF) in the alternate character set are displayed as MouseText characters (Figure 6-2) if the firmware is set to do so, or if the firmware is bypassed. • Note: The primary character set is normally displayed when the enhanced video firmware is inactive, and the alternate character set is normally displayed when the enhanced video firmware is active. The AltChar soft switch shown in Table B-5 can be used to control which character set is displayed. APPENDIX G Conversion Tables 619 Table G-6 Control characters ASCII Binary Dec Hex char Interpretation What to type Pri Alt 0000000 0 $00 NUL Blank (null) Control-§ 1 f 0000001 1 .$01 SOH Start of header Control-A A A 0000010 2 $02 STX Start of lext Control-B B 1$ 0000011 3 $03 ETX End of text Control-C C C 0000100 4 $04 EOT End of transm. Control-D D D 0000101 5 $05 ENQ Enquiry Control-E E E 0000110 6 $06 ACK Acknowledge Control-F F F 0000111 7 $07 BEL Bell Control-G G G 0001000 8 $08 BS Backspace Control-H oi Left Arrow-H H H 0001001 9 $09 HT Horizontal tab Control-I or Tab I I 0001010 10 $0A LF Line feed Control-J or Down Arrow-J J J 0001011 11 $0B VT Vertical tab Control-K or Up Arrow K K 0001100 12 $oc FF Form feed Control-L L L 0001101 13 $0D CR Carriage return Control-M ot Relurn M M oooi no 14 $0E SO Shift out Control-N N N 0001111 15 $0F SI Shift in Conlrol-0 O O 0010000 16 $10 DLE Data link escape Control-P P P 0010001 17 $11 DC1 Device control 1 Control-Q Q Q 0010010 18 $12 DQ Device control 2 Control-R R R 0010011 19 $13 DC3 Device control 3 Control-S S S 0010100 20 $14 DC4 Device control 4 Control-T T T 0010101 21 $15 NAK Neg. acknowledge Control-U or Right Arrow U U 0010110 22 $16 SYN Synchronization Control-V V V 0010111 23 $17 ETB End of text block Control-W w w 0011000 24 $18 CAN Cancel Control-X X X 0011001 25 $19 EM End of medium Control-Y Y Y 0011010 26 $1A SUB Substitute Control-Z Z Z 0011011 27 $1B ESC Escape Control-! or IJsc [ [ 0011100 23 $1C FS File separator Control-\ \ \ 0011101 29 $1D GS Group separator Control-) 1 1 0011110 30 $1E RS Record separator Control-^ A A 0011111 31 $1F US Unit separator Control-. _ _ 620 Apple lie Technical Reference Table G-7 Special characters ASCII Binary Dec Hex char Interpretation What to type Pri Alt 0100000 32 $20 SP Space Spacebar 0100001 33 $21 i 0100010 31 $22 % 0100011 35 $23 # I # 0100100 36 $24 $ $ $ 0100101 .37 $25 % % % 0100110 .38 $26 & & & 1 1 1 0100111 39 $27 Apostro 0101000 40 $28 ( ( ( 0101001 41 $29 ) ) ) 0101010 42 $2A « 0101011 43 $2B + 0101100 44 $2C J Comma 0101101 45 $2D - Hyphen 0101110 46 $2E Period 0101111 47 $2F / / / 0110000 48 $30 0 0 0 0110001 49 $31 1 1 1 0110010 50 $32 2 2 2 0110011 51 $33 3 3 3 0110100 52 $34 4 4 4 0110101 53 $35 5 5 5 0110110 51 $36 6 6 6 0110111 55 $37 7 7 7 0111000 56 $38 8 8 8 0111001 57 $39 9 9 9 0111010 58 $3A 0111011 59 $3B ) ! J 0111100 60 $3C < < < 0111101 61 $3D = V - 0111110 62 $3E > > > 0111111 63 $3F J ? ? APP ENDIX G Conversion Tables 621 Table G-8 Uppercase characters ASCII Binary Dec Hex char Interpretation What to type IVi Alt 1000000 64 $40 9 8 m 1000001 65 $41 A A 6 1000010 66 $42 B B K 1000011 67 $43 C C X 1000100 68 $44 D D • 1000101 69 $45 E E 1000110 70 S46 P F a * 1000111 71 S47 G G K. 1001000 72 $48 il II <- 1001001 73 S49 I I M 1001010 74 $4A J 1 * 7 * 1001011 5 $4B K K 1001100 76 $4C L L 1001101 77 $4D M M •J 1001110 ^8 S4E N N I 1001111 79 S4F 0 0 ± 1010000 80 $50 P P •>: 1010001 81 $51 Q Q +: 1010010 82 $52 R R *. 1010011 S3 $53 S S 1010100 84 $54 T T L 1010101 85 $55 U U -» 1010110 86 $56 V V * 1010111 87 $57 W w li 1011000 88 $58 X X Y c 1011001 39 $59 Y = 1011010 90 $5A Z z 1 1011011 91 $5B [ Opening Bracket I • 1011100 92 $5C \ Reverse Slant \ _ 1011101 93 $5D 1 Closing Bracket I # 1011110 94 S5E Caret 3 1011111 95 S5F Underline ' If lhe high bit is set, the MouseText characters are replaced with their equivalent in the primary character set with that value. 622 Apple He Technical Reference Table G-9 Lowercase characters ASCII Binary Dec Hex char Interpretation What to type Pri Alt 1100000 % $60 •• Grave accent 1100001 T< $61 a /w a 1100010 % $62 b b 1100011 99 $63 c ft c 1100100 100 $64 d $ d 1100101 101 $65 e % e 1100110 102 $66 f & f t 1100111 103 $67 8 8 1101000 101 $68 h ( h 1101001 105 $69 i ) i 1101010 106 S6A j • • 1101011 107 $6B k + )k 1101100 108 $6C 1 i 1 1101101 109 $6D m - m 1101110 110 $6E n n 1101111 111 $6F 0 / 0 1110000 112 $70 P 0 P 1110001 113 $71 q 1 q 1110010 114 $72 r 2 r 1110011 115 $73 s 3 s 1110100 116 $74 t 4 t 1110101 117 $75 u 5 u mono 118 $76 v 6 V 1110111 119 $77 w 7 w 1111000 120 $78 X 8 x 1111001 121 $79 y 9 y 1111010 122 $7A z * z 1111011 123 $7B ( Opening brace 1111100 124 $7C 1 Vertical line 1111101 125 $7D ) Closing brace 1111110 126 $7E - Overline (tilde) 1111111 127 $7F DEL Delete/rubout DEL APPENDIX G Conversion Tables 623 Appendix H Controlling the Apple He Plus Accelerator This appendix describes how an assembly-language program can control the cache glue gate array (CGGA) chip in the Apple He Plus and provides code samples that you can incorporate into your program. This information is provided for the sake of completeness only. Any code that changes speed settings for ports or lhat disables the CGGA cannot be run on any machine other than the Apple lie Plus. Any code that does not strictly adhere to the guidelines in this appendix is guaranteed not to work on future versions of the Apple lie Plus. See the section The Apple lie Plus Cache Glue Gate Array (CGGA)" in Chapter 11 for a general description of the CGGA and for approved methods of controlling the speed of the Apple He Plus. • 625 When the Apple He Plus is switched on or reset, ROM code for ports 1,2,5, and 6, and the code for the speaker and game paddles cannot be cached; this code is restricted to running at 1.023 MHz. The code for ports 3,4, and 7 can be cached, and so can run at up to 4 MHz. These settings were chosen to allow code written for other Apple II computers to run on the Apple he Plus; we recommend that you never change these settings. Before you decide whether or not to change these default settings or disable the CGGA, consider the following points: • Writing a 1 to any CGGA control word bits thai are reserved can cause the system to crash. The Write command is described later in this appendix. • Invalid data in a CGGA command can cause the system to crash. • Executing a CGGA command changes the state of the DHiRes switch, altering the state of graphics screens. You must return the DHiRes switch to its original state when you are finished executing any CGGA command. • If you speed up port 2, the Wail routine in firmware (see Appendix F) runs al 4 MHz ralher than 1 MHz. Use the Wait routine in the code sample at the end of this appendix instead. • If you speed up port 2, modem code might fail to work correctly. • If you speed up ports 5 and 6, the disk drives no longer funclion. • If the ROM isn't switched in before you execute a CGGA command, the system will crash. If RAM was switched in before you started, remember to return the RdLCRAM soft switch to its prior state before quitting. • If you attempt to speed up the game paddles, they no longer function. • Executing the Write command to the CGGA when the CGGA is disabled causes unpredictable results. You must be sure the CGGA is enabled before executing lhe Write command. • There is no way to determine the state of the system's speed at any given time—many factors cause it to change frequently. • If you execute a command to the CGGA on any machine other than the Apple He Plus, lhe system will crash. • Making changes to the state of the CGGA can cause other applications to work incorrectly. • Any or all of the above caveats may change with future revisions of the Apple He Plus hardware and firmware. 626 Apple He Technical Reference If your program makes any changes in CGGA settings, you must restore the CGGA to its original state before your program exits. Any changes in CGGA settings can prevent another application from running properly. Each time the system is reset, the Reset handler returns the CGGA to the default settings described at the beginning of this section; if your application quits by resetting the system, your program does not have to reset the CGGA CGGA commands This section describes how lo make calls to the CGGA to enable it, disable it, and change its mode of operation. • Warning Modifying the accelerator registers without a full understanding of the CGGA and the Apple He Plus hardware and firmware can render the system inoperative, requiring the user to shut the machine off and turn it back on again to regain control, A r To send a command to the CGGA, you must first push the command parameters onto the stack, then execute a JSR instruction to the accelerator entry point, $C7C7. The parameters consist of a pointer to a buffer (when necessary) and a command number. For your convenience, sample code is provided with each command description showing the proper way to set up the parameters for that call. The CGGA firmware pulls the parameters off the stack and checks the command number to determine if it corresponds to a valid command. If the command number is valid, lhe firmware performs lhe function specified by the command and returns to the calling routine with a value of $00 in the A register (accumulator). If the command number is not valid, the firmware returns the value $01 in the A register to indicate an error. In either case, the c (carry) flag is set. The calls themselves do not relurn errors. If the command number is valid, the firmware assumes that the parameters provided are also valid. APPENDIX H Controlling the Apple He Plus Accelerator 627 Before sending a command to the CGGA, you must be sure that the lower half of lhe ROM (lhe main ROM) is selected and that the ROM is switched in. To determine whether lhe main ROM is selected, check the contents of location $FCFF. If SFCFF contains a nonzero value, the main ROM is selected. • Warning The system will crash if you send a command to lhe CGGA when lhe main ROM is not both selected and switched in. • 628 Apple lie Technical Reference $01 Enable Accelerator Description It is possible for an application program to disable the CGGA completely. The Enable Accelerator command reenables the CGGA. Command number $01 Parameter list Command number Example Ida #$01 /Enable Accelerator command pha /Command pushed on stack jsr Accelerator_Entry /Jump to the Accelerator /entry point $02 Disable Accelerator Description The Disable Accelerator command disables the CGGA completely. The Apple lie Plus operates at 1 MHz as if there were no CGGA chip installed. Command number $02 Parameter list Command number Example Ida #302 / D i s a b l e A c c e l e r a t o r command pha /Command pushed on s t a c k jsr Accelerator_Entry /Jump t o t h e A c c e l e r a t o r /entry point APPENDIX H Controlling the Apple Be Plus Accelerator 629 $03 Lock Accelerator Description The Lock Accelerator command locks the CGGA so that it cannot receive any commands except for the Unlock Accelerator command. Command number $03 Parameter list Command number Example Ida #$03 /Lock Accelerator command pha /Command pushed on stack jsr Accelerator_Entry /Jump to the Accelerator /entry point $04 Unlock Accelerator Description The Unlock Accelerator command reverses the effect of the Lock Accelerator command, making it possible for the CGGA to accept all commands. Command number $04 Parameter list Command number Example Ida #$04 /Unlock Accelerator command pha /Command pushed on stack jsr Accelerator_Entry /Jump to the Accelerator /entry point 630 Apple lie Technical Reference $05 Read Accelerator Description The Read Accelerator command reads the CGGA registers, codes the state of the registers into a 2-byte word known as the control word, and places the control word in a buffer defined by the calling routine. The coding for the control word is shown in Table H-l. Table H-l Accelerator control word Bit Meaning Low byte 7 Speaker speed (1 = fast) 6 Port 7 speed (1 • fast) 5 Port 6 speed ( 1 :• fast) 4 Port 5 speed ( 1 '= fast) 3 Port 4 speed (1 •= fast) 2 Port 3 speed (1 =• fast) 1 Port 2 speed (1 • fast) 0 Port 1 speed (1 == fast) High byte 7 Reserved 6 Paddle speed (1 • slow) 5 Reserved 4 Reserved 3 CGGA enable (1 • disabled)' 2 Reserved 1 Reserved 0 Reserved • This bit is set and cleared by the Disable Accelerator and Enable Accelerator commands, not by the Write Accelerator command. For the Write Accelerator command, this bit is reserved. APPENDIX H Controlling the Apple He Plus Accelerator 631 Command number $05 Parameter list Command number Pointer to buffer in which to store the control word da Example ^ Ida #buffer /Low byte of buffer address pha /Byte pushed on stack Ida #$05 /Read Accelerator command pha /Command pushed on stack jsr Accelerator Entry /Jump to the Accelerator /entry point 632 Apple He Technical Reference $06 Write Accelerator Description The Write Accelerator command sends a control word to the CGGA, resetting the values in the CGGA's internal registers. You can use this command to control which ports in the Apple lie run at 1 MHz and which run at 4 MHz. The CGGA control word is shown in Table H-l. Notice that you use the Enable Accelerator and Disable Accelerator commands to set or clear bit 3 of the high byte; do not write to this bit. All other bits are set by the Write Accelerator command. A Important Executing the Write command to the CGGA when the CGGA is disabled causes unpredictable results. Use the Read command—and then the Enable command if necessary—to make sure the CGGA is enabled before executing the Write command, A Command number $06 Parameter list Command number Pointer to buffer in which the control word is stored Example Ida #buffer /Low byte of buffer address pha /Byte pushed on stack Ida #S06 /Write Accelerator command pha /Command pushed on stack jsr Accelerator Entry /Jump to the Accelerator /entry point APPENDIX H Controlling the Apple He Plus Accelerator 633 Code sample The following code sample constitutes a shell that goes around any calls you make to the CGGA. Several routines are provided; use only those that you need. The code sample includes the following routines: • The main routine that calls the other subroutines. • A routine that checks the ID bytes of the computer to determine if it is an Apple lie Plus. If you are certain that the machine is an Apple He Plus, you don't have to check it again, but remember that any CGGA call causes any Apple II computer otherlhan an Apple lie Plus to crash. R A routine that saves the states of the DHiRes and 8OC0I soft switches and turns off 80-column mode before you send any commands to the CGGA. If you can make your calls to the CGGA at lhe beginning of your program before selling the DHiRes switch and 8OC0I switch, then you do not have to use this routine. Just be sure to set the DHiRes and 8OC0I switches to the settings you want after you have finished sending commands to the CGGA. Remember also to switch in the main ROM before sending any commands to the CGGA, and to return the RdLCRAM soft switch to its prior state when you are finished. • A routine that restores the saved state of the machine. • A routine that unlocks the CGGA so that it can receive commands. You must use this routine before sending any commands to the CGGA. • A rouline that locks the CGGA so that no additional commands can be sent to it during normal system use. You must use this routine before quitting. • A routine that you can use instead of the firmware version of the Wait routine (described in Appendix F) if your program speeds up port 2. 634 Apple lie Technical Reference *using the accelerator: * •This code implements any of the calls documented *in this section that talk to the accelerator In the lie Plus. * Entry: ROM must be enabled w * Exit: C=0 * A=0 * X,Y undefined use.accel accel.entry equ $C7C7 /entry point to talk to accelerator jsr check . id /must be at least a H e Plus bec dont /won't work on any other machine jsr save.state /save state if you don't know what it is jsr unlock /must unlock it before anything else * •add your call(s) here. See descriptions of calls for format jsr lock /must lock it when all finished jsr restore. state /must restore it if you saved it dont rts ;go back to the calling routine or user APPENDIX H Controlling the Apple He Plus Accelerator 635 rw**W*r*w*****#K******l r»#***irw****«**i "check.id: Calls to the accelerator can ONLY be made on * a lie Plus. If this call is made on any ether * Apple II machine, the program WILL crash! * This routine checks for the current lie Plus and beyond (for future compatability). * * Entry: ROM must be enabled * * Exit: C=0 if not lie Plus * C=l if H e Plus A,X,Y undefined r#*****W*********1 r**-***********-*-**** check.id idl equ SFBB3 id2 equ SFBC0 id3 equ SFBBF Ida idl /should be $06 emp #$06 bne no /if not H e Plus then quit Ida id2 bne no /should be $00 — if not then quit Ida id3 /should be $> 5 bmi no /make sure it's not the orig lie with #SFF emp #$05 bcs done ;if c=0 then it failed-- make sure it does! clc /clear carry means wrong machine done rts /go back with status of test 636 Apple lie Technical Reference f****»ft********»»**I»*»»«*); and the System Monitor correctly be termed read-write memory) Compare program, an asterisk ('). read-only memory, read-write memory. prompt line: A specific area on the display random-access text file: A lext file that is reserved for prompts. partitioned into an unlimited number of uniform- length compartments called records. When you protocol A forma! set of rules for sending and open a random-access text file for the first time, receiving data on a communication line. you must specify its record length. No record is Protocol Converter: The name used for the first placed in the file until written to. Each record can version of the SmartPort firmware; the Protocol be individually read from or written to—hence, Converter was introduced with the UniDisk 3.5 random-access. Apple lie. See SmartPort. read To transfer information into the computer's push: To add an entry to the top of a stack, memory from outside the computer (such as a disk moving the stack pointer to point to it. Compare drive or modem) or into the computer's processor pop. from a source external to the processor (such as the QWERTY keyboard See Sholes keyboard keyboard or main memory). radio-frequency (RF) modulator: A device thai read-only memory (ROM): Memory whose makes a television set work as a monitor. contents can be read, but not changed; used for storing firmware. Information is placed into read- RAM: See random-access memory. only memory once, during manufacture; it then remains there permanently, even when the computer's power is lurned off. Compare random- access memory, read-write memory. Glossary 661 read-write memory: Memory whose contents RGB monitor: A type of color monitor that can be both read and changed (or written to). The receives separate signals for each color (red, green, information contained in read-write memory is and blue). erased when the computer's power is turned off ROM: See read-only memory. and is permanently lost unless it has been saved on routine: A part of a program that accomplishes a disk or other storage device, Compare random- some task subordinate to the overall task of the access memory, read-only memory. program. real number: In computer usage, a number thai row: A horizontal arrangement of character cells or may include a fractional part; represented inside the graphics pixels on the screen. computer in floating-point form. Because a real number is of infinite precision, this representation RS-232 cable: Any cable that is wired in is usually approximate. Compare integer. accordance wilh the RS-232 standard, which is the common serial daLa communication interface receive data register: A read-only register in the standard. serial port ACIA (at $C098 for port 1 and SC0A8 for port 2) that stores the most recent character RTS: See Request-To-Send successfully received. run: (1) To execute a program. When a program register: A location in a processor or other chip runs, the computer performs the instructions. where an item of information is held and modified (2) To load a program into main memory from a under program control. An area of memory used peripheral storage medium, such as a disk, and for a similar purpose. execute it, relational operator: An operator, such as > save: To store information by transferring the (greater than), lhat operates on numeric values to information from main memory to a disk. Work produce a logical result. Compare arithmetic not saved disappears when you turn off the operator, logical operator. computer or when the power is interrupted. Request-To-Send An RS-232-C signal from a DTE screen: See display screen. to a DCE that serves to prepare the DCE for data screen hole: An address in memory that is within transmission. the range assigned lo video dislplay, but that is not reserved word A word or sequence of characters actually used by lhe video display. Screen holes are reserved by a programming language for some used by the I/O firmware in a variety of ways. special use and therefore unavailable as a variable scroll To move all the text on the screen upward name in a program. or downward, and, in some cases, sideways. resident* See memory-resident, disk-resident serial interface: An interface in which return address: The point in a program to which information is transmitted sequentially, a bit at a conlrol returns on completion of a subroutine or lime, over a single wire or channel. Compare function. parallel interface. RF modulator: See radio-frequency modulator. 662 Apple lie Technical Reference setup time*. The amount of time a signal must be soft switch: Also called a software switch; a means valid in advance of some event. Compare hold of changing some feature of the computer from time. within a program. A soft switch is a location in Sholes keyboard The standard layout of keys on memory that produces some special effect a typewriter keyboard; its name is formed from whenever its contents are read or written. the first six letters on the lop row of letter keys. software: A collective term for programs, the Also called a QWERTY keyboard. Compare Dvorak instructions that tell the computer what to do. keyboard They're usually stored on disks. Compare silicon (Si): A solid, crystalline chemical element hardware, firmware. from which integrated circuits are made. Silicon is a source code: See source program. semiconductor; thai is, it conducts electricity source program: The form of a program given to better than insulators, but not as well as metallic a language translator, such as a compiler or conductors. Silicon should not be confused with assembler, for conversion into another form; silica—that is, silicon dioxide, such as quartz, opal, sometimes called source code. Compare object or sand—or with silicone, any of a group of organic program. compounds containing silicon. space character: A text character whose printed simple variable: A variable that is not an representation is a blank space, typed from the element of an array. keyboard by pressing the Space bar. 68000: The microprocessor used in lhe Macintosh SPACE parity: A bit value of 0 appended to a and Macintosh Plus. binary number for transmission. The receving 6502: The microprocessor used in the Apple II, in device can look for this value on each character as a the Apple II Plus, and in early models of the means of error checking. Compare even parity, Apple lie. MARK parity, odd parity. 65C02: lhe microprocessor used in the enhanced S register: See stack pointer. Apple Be, the extended keyboard Apple He, and stack: (1) A list in which entries are added the Apple He family of computers. (pushed) or removed (popped) at one end only (the slot: A long, narrow socket inside the computer top of the stack), causing them to be removed in where you can install peripheral cards. Also called an last-in, first-out (LIFO) order. (2) The portion of expansion sbt. memory in page $01 used as a stack for 65C02 SmartPort firmware: A set of machine language programs. Certain 65C02 instructions push bytes of routines in all Apple Ilc-family computers except data onto the stack or pull bytes of data from the the original Apple Be. The SmartPort firmware is stack. used for performing block device 1/0. The version stack pointer: An 8-bit register in the 65C02 of the SmartPort firmware used in the UniDisk 3.5 microprocessor that points to the next byte of Apple He computer was called the Protocol data to be used for the microprocessor's stack. Converter. The SmartPort firmware and the standard Input Data input by calls to the Protocol Converter are functionally identical. firmware routine Keyln. Glossary 663 standard output Data output by calls to the subroutine: A part of a program that can be firmware routine COul. executed on request from another point in the start bit A transition from a MARK signal to a program and that returns conlrol, on completion, SPACE signal for one bit-time, indicating that next to the point of the request. string of bits represents a character. Super Serial Card A peripheral interface card starting value: The value assigned to the index used with the Apple He computer. The Super Serial variable on the first pass through a loop. Card interfaces perpheral devices—such as printers and modems—that use a serial data stream for start up: To get the system running. Starting up is communications. The serial ports in the Apple lie the process of first reading the operating system family use a protocol very similar to that used by program from lhe disk, and then running an the Super Serial Card. application program. Starting up is often called booting. synchronous: A mode of data transmission in which a constant time interval exists between startup disk: A disk with all the necessary transmission of successive bits, characters, or program files to set the computer into operation. events. Compare asynchronous. Sometimes called a boot disk. synchronous transmission: A transmission statement A unit of a program in a high-level process lhat uses a clocking signal to ensure an language lhat specifies an action for the computer integral number of unit (time) intervals between to perform. A statement typically corresponds to any two characters. Compare asynchronous several instmctions of machine language. transmission. status register: A location in the ACIA (at $C099 syntax: (1) The rules governing the structure of for port 1 and $C0A9 for port 2) that stores the statements or instructions in a programming state of two RS-232-C signals and the state of the language. (2) A representation of a command lhat transmit and receive data registers, as well as the specifies all the possible forms the command can outcome of the most recent character transfer. take. step value: The amount by which the index system: A coordinated collection of interrelated variable changes on each pass through a loop. and interacting parts organized to perform some stop bit A MARK signal following a data string function or achieve some purpose—for example, a (or the optional parity bit), indicating the end of a computer system comprising a processor, character. keyboard, monitor, and disk drive. string: An item of information consisting of a system configuration: See configuration. sequence of text characters. System Monitor: A system program built into strobe: A signal whose change is used to trigger the firmware of the Apple lie, used for directly some action. inspecting or changing the contents of main memory and for operating the computer at the machine-language level. 664 Apple He Technical Reference system program: A program that makes the transistor-transistor logic (TTL): (1) A family resources and capabilities of the computer available of integrated circuits having bipolar circuit logic; for general purposes, such as an operating system TTLs are used in computers and related devices. (2) or a language translator. Compare application A standard for interconnecting such circuits, which program. defines the voltages used to represent logical zeros system software: The component of a computer and ones. system that supports application programs by transmit data register: A location in the ACIA managing system resources such as memory and (at location $C098 for port 1 and $C0A8 for port 2) I/O devices. that holds the current character to be transmitied. tab: An ASCII character thai commands a device troubleshoot To locate and correct the cause of such as a printer to start printing al a preset a problem or malfunction, especially in hardware. location (called a tab stop). There are two such Compare debug characters: horizontal tab (HT, $09) and vertical tab TTL See transistor-transistor logic. (VT, SOB). unary operator: An operator that applies to a television set A display device capable of single operand. For example, the minus sign (-) in a receiving broadcast video signals (such as negative number such as -6 is a unary arithmetic commercial television broadcasts) by means of an operator. Compare binary operator. antenna. Can be used in combination with a radio- unconditional branch: A branch that does not frequency modulator as a display device for the depend on the truth of any condition. Compare Apple II family of computers. Compare video conditional branch. monitor. value: An item of information, such as a number text: (1) Information presented in the form of or a string, that can be stored in a variable. readable characters. (2) The display of characters on a display screen. Compare graphics. variable: (1) A location in the computer's memory where a value can be stored. (2) lhe symbol used in text window: An area on the video display screen a program to represent such a location. Compare within which text is displayed and scrolled. constant. timing generator (TMG): The custom VBL: Mnemonic for vertical blanking. See integrated circuit that generates clock and liming vertical blanking signal, vertical blanking signals used by the Apple He. interrupt. TMG: See timing generator. vector: (1) An address of a location in memory, traces: Electrical paths that connect the often the starting address or entry point for a components on a circuit board. special routine. Application programs and operating systems use vectors to get to an address quickly. (2) A memory location used to hold a vector, or the address of such a location. Glossary 665 vertical blanking interrupt: An interrupt to the window: The portion of a collection of CPU syncharonized wilh the vertical blanking information (such as a document, picture, or signal. See also vertical blanking signal worksheet) that is visible in a viewport on the vertical blanking signal A signal used to display screen. Compare viewport. synchronize the turning off (blanking) of the word A group of bits that is treated as a unit; the electron beam in the video display with the return number of bits in a word is a characteristic of each of the beam from the bottom to lhe lop of the particular computer. In the Apple Be family of screen. In the Apple Ilc-family computers, the computers, a word is 16 bits (2 bytes) long. vertical blanking signal is asserted 60 times each write: To transfer information from the second. See also vertical blanking interrupt computer to a destination external to the video: (1) A medium for transmitting information computer (such as a disk drive, printer, or modem) in the form of images to be displayed on the screen or from the computer's processor to a destination of a calhode-ray tube. (2) Information organized or external to the processor (such as main memory). transmitted in video form. write-enable notch: The square cutout on one video monitor: A display device that can receive edge of a 5.25-inch disk's jacket. If there is no video signals by direct conneclion only, and that write-enable notch, or if it is covered wilh a write- cannot receive broadcast signals such as protect tab, the disk drive can read information commercial television. Can be connected directly to from the disk, but cannot write on it. the computer as a display device. Compare XOR: Exclusive-OR. A Boolean (logical) operation television set. that produces a true (1) result if one and only one viewport All or part of the display screen used by of its inputs is true (1). Compare OR, AND, and an application program to display a portion of the NOT. information (such as a document, picture, or X register: One of the two index registers in the worksheet) on which a program is working. 6502 microprocessor. Compare window. Y register: One of the two index registers in the volume: A general term referring to a storage 6502 microprocessor. device; a source of or a destination for information. zero page: The first page (256 bytes) of memory A volume has a name and a volume directory wilh in the Apple II family of computers, also called the same name. Its information is organized into page zero. Since the high-order byte of any address files. in this page is zero, only the low-order byte is warm start The process of putting the Apple lie needed to specify a zero-page address; this makes into a known state. Depending on what operating zero-page locations more efficient to address, in system and application program, if any, are running both time and space, than locations in any other when the warm start takes place, lhe computer page of memory. may wind up back in the operating sytem or at the startup point for an application program. Compare cold start. 666 Apple He Technical Reference Index A '(asterisk) xxxiii,59 accelerator \ (backslash) 112,114 disabling 629 A (caret) 291 enabling 629 S (dollar sign) xxxiii, 291 locking 630 . (period) 271 code sample 638 ? (question mark) 112,193 reading 631 _ (underscore) 193 unlocking 630 80-column text 146 code sample 638 80/40-column switch 10,31 using 41 80COL soft switch 153,157 writing to 633 80Store soft switch 73, 157 accelerator circuit 329. See also CGGA 40-column text 146 enabling and disabling 333 48K address space 48,63-76 accumulator. See A register map of 65 ACIA page allocations 64 block diagram 384 switching 67-69 buffering 102 6502 458 command register 389 6502A 458 control register 388 65C02 41,312-317. See also registers, 65C02, and interrupts 96 419-431,458 pinouts 385 addressing modes 292 signals 385,386 block diagram 312 status register 390 clock rate 312 transmit/receive register 391 data sheet 422 address bus 335 differences from 6502 420 addresses 433 instructions 292 SCOOO-SCOOF 461 specifications 314 $C010-$C01F 462 timing 314 $C02O-$CO2F 462 Apple lie Plus 315 SC03O-$CO3F 462 SC040-$C04F 462 SC050-SC05F 463 SCO50-SC06F 463 667 $C070-$C07F 464 and mouse 261 SC080-SC08F 464 AppleTalk 172 $C090-$C09F 464 Apple lie features 456 display page maps 160 Apple lie Plus SFFFE 91 accelerator 41 $45 90 appearance 27-29 hardware 444 features 26-^0,457 different machines compared 461 interior 37 addressing keyboard 29 video display memory 360 Apple He features 457 addressing modes 292 Apple II features 456 address maps 47-52 Apple IIGS 138,455 48K65 and Init call 230 address pages identifying 584 500 address page 53 Apple 11 Plus features 456 501 address page 54 Apple II routine 534 502 address page 64 A register (accumulator) 41 503 address page 64,439 loading 564 S04-S07 address pages 64 printing 515,579,580 $08 address page 66 arithmetic, hexadecimal 280 $O8-$0B address pages 66 arrow keys 9 S20-S3F address pages 67 ASCII character set S40-S5F address pages 67 basic table 493 SCO address page 52 expandable table 620-623 SD0-$FF address pages 54 ASCII codes address space for British key board 483 expansion ROM 127 for Canadian key board 486 Advance routine 546 for French key board 484 advancing the cursor 546 for German key board 487-^188 AltChar soft switch 157 for Italian key board 490 alternate character sel 122, 143,468 for USA key board 132-133 AltZP 56 for Western Spanish key board 491-492 ANSI 478 assembly language APDA xxxiv debugging 287 Apple Developer Services xxxv disassembler 285,587 Apple keys. See Command key, Option key mini-assembler 289-293 Applesoft BASIC 88, 453 asterisk (') xxxiii, 59 interpreter 51 AUD 356 and I/O links 110 audio output machines compared 467 668 Apple lie Technical Reference audio output jack 14,35,358 serial port 383 automatic repeat 9 video display 366 auxiliary memory. See auxiliary RAM board versus card xxxiii auxiliary RAM 48,50,69 boldface xxxii transferring control 71 boot. See resets auxiliary ROM 48,51 break handler 521,522,523 break instruction 95,128 B Break routine 522 back panel connectors BREAK signal 183 British keyboard 482 Apple He 16 BRK. See break instruction Apple lie Plus 36 BS routine 548 backslash (\) 112,114 buffer, serial I/O 102,471 backspace 114,548 button interrupt mode 255 Bank 1 48,54 bytes 612 Bank 2 54 bank-switched memory 48,53-63. See also 4RK. memory C selector switches 54-63 cache, data 329 BasCalc rouline 541 ache glue gate array. See CGGA BASIC 88,453 CALL-151 command 604 interpreter 51 Canadian keyboard 485 and I/O links 110 cancel line 114 and mouse 26l Caps Lock key 9,478 baud 183 card versus board xxxiii Bell routine 136,598 caret (A) 291 Belli routine 136, 542 carriage return Belli.2 rouline 543 CR routine 554 Bell2 routine 544 CROut rouline 577 bits 612 CROutl routine 576 blank spaces Sending to printer 185 printing 517,518 carrier signal 183 block devices casselle I/O 475 I/O 201 certified developer xxxv block diagrams CGGA 315,329. 5ee a/so accelerator circuit 65C02 312 commands 627-633 ACIA 384 Disable Accelerator 629 Apple He 301 Enable Accelerator 629 Apple He Plus 303 Lock Accelerator 630 keyboard circuit 351 Read Accelerator 631 INDEX 669 Unlock Accelerator 630 commands Write Accelerator 633 CGGA 627-633 pinouts 330 Monitor 292 signal descriptions 331-333 SmartPort 247 changing contents of registers 277 communications devices 192 changing memory contents 273 comparing data in memory 276, 586 character generator 369 components charactersets 120-122,143,468,619-623 Apple He 5-23 characters, normal 121,143,468 Apple lie Plus 27 SetNorm routine 589 memory expansion Apple lie 25 circuit diagrams connectors hand conlrol 400 Apple He back panel 16 mouse 395 Apple lie expansion 405 speaker 357 Apple lie external power 305 ClampMouse rouline 259 Apple He internal power 307 clearing Apple lie Plus back panel 36 line of text 557,558 Apple Be Plus internal power 311 Lo-Res graphics screen 504 external disk drive 378 mixed-mode display 505 Apple lie Plus signals 379 text screen 534,552 Apple lie signals 379 ClearMouse routine 259 hand control 397 clock rate 312 internal disk drive 380 clock signals 314 Apple lie Plus signals 381,382 Close all 232 Apple He signals 381 Closed Apple key. See Option key internal modem 406 ClrEOL routine 557 keyboard 352 ClrEOLZ routine 558 memory expansion card 403 ClrEOP routine 552 mouse 394 ClrScr rouline 504 serial port ClrTop routine 505 Apple lie 386 cold start 83-87,525. See also startup Apple Be Plus 387 color. See also graphics modes video 374 Double Hi-Res graphics 152 video expansion Hi-Res graphics 149,371 pinouts 376 Lo-Res graphics 147, 508 signals 376,377 NxlCol routine 507 conlrol, transferring between main and auxiliary Scrn routine 510 RAM 71 SetCol rouline 508 Conlrol a l l 227 Command key xxxiii, 10,31 control characters andC3COutl 117 670 Apple He Technical Reference and COutl 116 serial 183,191 and PWrite 170 debugging 287 sending to the printer 185 decimal conversion to hexadecimal 615 Control key 9 defaults. See also initial state Control-Command-Rcset 87 serial portl 179 Control-P command 280 serial port 2 187 Control-Reset 89 delays conventions xxxii Wait routine 559 copying data between main and auxiliary RAM 70 Wait routine code with accelerator 639 copying data in memory 275,585 developer services xxxv COul routine 116,154,581 device conlrol block 217,228 COutl routine 116,121,582 device information block 218 conlrol characters 116 device status block 216 COutZ rouline 583 DHiRes soft switch 73, 158 CP/M 452 diagnostic code 88 CPU. Sa?65C02 Dig routine 606 CROut routine 577 direct memory access 465 CROutl routine 576 disassembler 285 CR routine 554 disassembling instructions 285 CRT. See video display InstDsp routine 513 CSW 109,156 List rouline 587 C3COutl routine 116,122,582 disk controller 325-327 control characters 117 disk drive connectors C3KeyIn routine 115,567 for external drive 378-379 cursor movement for internal drive 380-382 Advance routine 546 disk drive opening CR routine 554 Apple He Plus 35 Home routine 553 original Apple lie 15 keys 9 disk drive ports 202-204 LF routine 555 disk drives custom ICs 476 different machines compared 469 cycle for 65C02 instructions 420 I/O 202-204 options 211 D startup drive 84, 211 data bus 335 disk eject button 35 data format for serial data transfer 184 disk I/O 377-382 data transfer disk-use light 14, 34 between main and auxiliary RAM 70 display. See video display sending control characters 185 display formats 143 INDEX 671 display memory maps 160— 166 firmware 495-609 display modes 365 mouse port 252 Double Hi-Res graphics 152 environmental specifications 298 graphics 147,154 error codes, SmartPort 248 Hi-Res graphics 149 Esc key 10,31 Lo-Res graphics 147 escape mode memory address bits 363 RdChar routine 569 mixed-mode 154 sequences 112 soft switches 156-159 even parity 184 text 143 Examine command 278 display pages 64-66,67,155 examining contents of registers 278 switches 72-75 examining memory 270 display window. See text window Execute call 239 DMA 465 executing a program 285 dollar sign (S) xxxiii Go routine 594 DOS 452 expansion ard memory 46l and I/O links 110 expansion connector 405 and the reset vector 88 expansion ROM space 127 DOS 3.3 110 Extended 80-Column Text Card 460 Double Hi-Res graphics 152,372 Download call 241 dumping memory 271 FD10 routine 565 duplex 194,196 features Dvorak keyboard 11, 32 Apple lie 4-23 Dvorak switch 10, 31 Apple He Plus 26-40 dynamic RAM. See RAM memory expansion Apple He 24-26 UniDisk 3.5 Apple lie 23-24 firmware. See also ROM arphones 14,358 enhanced video 140-142 echo 198 entry points 496-609 editing with GetLn 114-115 I/O links 108 80-column text 146 interrupt support 128 80/40-column switch 10,31 keyboard input 134 80COL soft switch 153,157 mouse 257 80Store soft switch 73,157 routines 496-609 Eject all 238,239 speaker output 136 English keyboard 482 standard entry points 124,168 enhanced video firmware 140-142 firmware protocol 124 entry points mouse 260 672 Apple lie Technical Reference serial port 1 181 NxtCol routine 507 serial port 2 188 Plot routine 500 video (port 3) 168 Plotl routine 501 flashing text 120,143 San routine 510 forced cold reset 87 SetCol routine 508 Format call 225 VLine routine 503 format of serial data 184 green light 14,34 Fortran 454 40-column text 146 H 48K address space 48,63-76 half duplex 194 map of 65 hand controls 397^102 page allocations 64 analog inputs 265 switching 67-69 circuit diagram 400 French keyboard 483 connecting switch inputs 399 full duplex 196 connector 397 different machines compared 474 rading 527,528 game paddle. See hand controls signals 398,401 game port 264 switches 265 GBasCalc routine 506 using mouse as 263 general logic unit 324 hardware, different machines compared 475 GetLn 111-115 hardware addresses 444 esape sequences 113 different machines compared 461 prompt character 112 headphones 14, 358 GetLn routine 572 HeadR routine 563 GetLnO routine 574 hexadecimal GetLnl routine 134,575 conversion to decimal 614 GetLnZ rouline 134,571 conversion to negative decimal 615 GetNum routine 607 hexadecimal arithmetic with the Monitor 280 GLU chip 324 high-resolution graphics. See Hi-Res graphics; Double Go command 285 Hi-Res graphics Go routine 594 Hi-Res graphics 149-151,371-373 graphics modes 147-154. See also Lo-Res graphics; Hi-Res graphics P3ge 1 67 Hi-Res graphics; Double Hi-Rcs graphics Hi-Res graphics Page IX 67 graphics routines Hi-Res graphics Page 2 67 ClrScr routine 504 Hi-Res graphics Page 2X 67 ClrTop routine 505 HiRes 73 GBasCalc routine 506 HiRes soft switch 73, 157 HLine routine 502 HLine rouline 502 INDEX 673 HomeMouse routine 259 interrupt handler 90, 520 Home routine 553 built-in 91-93 HRP1 67 system 91 HRP1X 67 user's 94 HRP2 67 interrupt mode 254 HRP2X67 interrupt-handling sequence 92 humidity 298 interrupts 89-106,128,466 ACIA 101,106 I external 100 identification bytes 2,458,538, 539, 540 keyboard 98 identifotion code, sample 636 mouse 97,105 identification number, peripheral 617 sources 96 IDRoutine 584 inverse characters 588 IN#2 194,195,196,198 Inverse command 279 IN*n 123 inverse flag 588,589 index regislers 42 inverse lext 120,143 initialization. See resets displaying 279 initial state 80 I/O. See also serial ports; standard I/O Init.Mouse routine 259 block devices 201 Init routine 230, 529 disk 202-204,377-382 InPort routine 591 disk drives 202-204 input esapemode 112, 569 keyboard 130 memory expansion card 205 mouse 391 ports 123-128 standard 110 redirecting 280 input buffer I/O links 108-110,156,590,591,592,593 keyboard 66 IORTS routine 601 serial 66 IOU 320 input hook. See I/O links pinouts 321 input/output unit. See IOU signal descriptions 321 InsDsl.2 routine 511 and speaker 356 lnsDs2 routine 512 video display counters 359 InstDsp routine 513 IOUDis 73 Integer BASIC 453 IOUDis soft switch 73, 157 integrated circuits IRQ 90, 128 Apple He 21 ISO keyboards 478 Apple lie Plus 39 IWM 325-327 internal modem connector 406 international power supply 494 674 Apple He Technical Reference K KB xxxiii language card 48,54,459 KbdWait routine 537 languages 453-^54 Kbil xxxiii left margin 119 keyboards 130-134 LF routine 555 Apple lie Plus 29, 31 lights 14,34 ASCII codes 132-133,479-492 different machines compared 466 British 482 linefeed 185,193,555 buffering 99 USP 454 Canadian 485 List routine 587 codes 478 locking accelerator different machines compared 466 code sample 638 Dvorak 481 logic board French 483 Apple He 20 German 487 Apple He Plus 39 input characteristics 131 LogoII 454 and interrupts 98 Lo-Res graphics 64,66,147,369-370 ISO 482 low-resolution graphics 64,66,147, 367-370 Italian 488 layouts 47M91 M original Apple He 7-14 machine ID code sample 636 QWER1Y 479 machine identification 458 rading 130 machine language 284 Sholes 479 machine stale saving 637 signals 355 main logic board Western Spanish 490 Apple lie 20 keyboard circuit block diagram 351 Apple lie Plus 39 keyboard connector 352-354 main RAM 48,50 keyboard input buffer 66 MARK parity 184 keyboard layout switch 10, 31 MB xxxiii Keyln routine 115, 567 memory KeylnO routine 566 changing contents 273 keys ASCII codes 132-133 comparing data 276, 586 KSW 109,156 examining 270 moving data 275, 585 video display 360 memory. See RAM; ROM memory banks 48 INDEX 675 memory bus organization 335 Move 275,282 memory dump 271 Normal 279 memory expansion Apple lie Slep 287 appearance 25 Store 273 features 24-26 syntax of 269 memory expansion ard 27,46,402-105,460 Trace 287 connector 403 Verify 276,282 connector signals 404 command summary 294 I/O 206 comparing data in memory 276 and SmartPort 208 creating your own commands 284 starting up from 84 display inverse and normal texl 279 memory expansion port arlicr version 464 characteristics 206 examining contents of registers 278 memory management unit. See MMU examining memory 270 microprocessor. See65C02 filling memory 282 MIG chip 377 hexadecimal arithmetic 280 pinouts 327 invoking 268 signal descriptions 328 Mon routine 603,604 mini-assembler 293 MonZ4 routine 605 instruction format 292 OldRst routine 602 starling 290 machine-language programs 284 using 290 memory dump 271 mixed-mode display 154 mini-assembler 289-293 ClrTop routine 505 Mode byte 609 setting 531 moving data in memory 275 Mixed soft switch 157 multiple commands on one line 281 MMU chip 318 program counter 519 pinouts 319 quitting 279 signal descriptions 319 redirecting I/O 280 Monitor System 267-298 repeating commands 283 ASCII input mode 274 running a program 285 changing contents of registers 277 support for game input 266 changing memory contents 273 support for keyboard inpul 134 commands 269-296 support for speaker output 136 Control-P 280 support for video display output 167 Examine 278 Mon routine 603,604 Go 285 MonZ4 routine 605 Inverse 279 mother board. See main logic board List 285 mouse 676 Apple lie Technical Reference and BASIC 261 displaying 279 button signals 396 SetNorm routine 589 circuit 395 notation xxxiii connector 394 NTSC 359 firmware routines 257 NTSC monitor 138 as hand conlrol 263 NxtAl routine 562 initializing 258 NxtA4 routine 561 input 252-263,391,472 NxtChr rouline 608 and interrupts 97 NxtCol rouline 507 operating modes 253-255 button interrupt mode 255 O interrupt mode 254 odd parity 184 movement/button interrupt mode 255 OldBrk rouline 523 transparent mode 254 OldlRQ rouline 520 vertical blanking active modes 255 OldRst routine 602 andPasal 260 opcode, determining length 511,512 rading 527 Open Apple key. See Command key saeen holes 262 Open call 231 waveforms 392-393 operating conditions 298 mouse and game port 251 operating systems 452 mouse mode byte 258 Option key xxxiii, 10,31 mouse port original Apple He characteristics 252, 253 appearance 5-7 entry points 252 components 23 soft switches 255 features 4-23 MouseText 144,468 interior 19 MoveAux 69-71 keyboard 7-8 Move command 275,282 OutPort routine 593 movement/button interrupt mode 255 output Move routine 585 speaker 135 moving data in memory 275, 585 standard 115-122 multidrive interface glue (MIG) 327-328 video 138-171,373 video expansion 374 N output hook. See I/O links NewBrk routine 521 nibble 612 NMI 90 nonmaskable interrupt 90 normal text 120,143 INDEX 677 TMG 323 pages, address 47 64 Kbit RAM 341 $00 53 2316 ROM 337 $0154 23256 ROM 336 $02 64 2364 ROM 338 $03 64,80,439 256 Kbit RAM 312 $O4-$07 64 Video expansion connector 376 $08 66 Plot routine 500 S08-S0B 66 Plotl routine 501 S20-S3F 67 ports. See also specific ports S40-55F 67 address space 126 $00 52 entry points 123 $DO-$FF54 memory locations 126 Page2 soft switch 73,157 standard entry points 124,168 PAL display 359 versus slots 465 parity bit 184 PosMouse routine 259 Pasal 453 power light 14, 34 and interrupts 88,89, 90 power supplies 304-311 and mouse 260 Apple He 19,304 and window width 119 external power connector 305 Pascal Operating System 452 external transformer 304 pausing internal power connector 307 Wait routine 559 internal voltage converter 306 Wait routine code wilh accelerator 639 Apple He Plus 38,310 pausing display 536,537 internal power connector 311 PCAdj routine 519 different machines compared 475 period (.) 271 international 494 peripheral ard memory 46l PR#2 198 peripheral identification numbers (PIN) 617 PR#n 84,123 PInit 168 PrAl routine 578 pinouts PrBl2 routine 518 accelerator ache RAM 347 PrBlnk routine 517 ACIA 385 PrByte routine 579 GLU 324 PRead routine 169,527 IOU 321 PRead4 routine 528 IWM 326 P register 42 MIG 327 PrErr rouline 597 MIG RAM 346 PrHex routine 580 MMU 319 primary character set 121,143 678 Apple lie Technical Reference printer 64 Kbit RAM 341 sending conlrol characters 185 256 Kbit RAM 342 priming MIG RAM 346 A register 515,579,580 refreshing 340 blank spaces 517,518 signal descriptions characters to the screen 545, 547 ache data RAM 348 PrErr routine 597 ache tag RAM 349 registers 523, 526 MIG RAM 346,347 X register 514,515,516 64 Kbit RAM 341 Y register 514 256 Kbit RAM 342 priority startup 83 timing signals 344 PrnlAX routine 515 transfers between main and auxiliary 69 PrntX routine 516 RAM. See main RAM, auxiliary RAM PrntYX routine 514 RAM ache 329 processor types 458 RAM locations 433 processor. See65C02 RAMRd 68,72 Processor Status register 42 RAMWrt 68,72 ProDOS 452 RdAltChar soft switch 157 and I/O links 110 RdAltZP soft switch 56 and the reset vector 88 RdBnk2 soft switch 56 r prompt character 111 Protocol Converter 207. See also SmartPort RdChar routine 134,569 RdDHiRes soft switch 73, 158 PStatus 170 Rd80Col soft switch 157 PWrite 169 Rd80Store soft switch 73,157 control characters 170 RdliiRes soft switch 73, 157 PwrUp routine 525 RdlOUDis soft switch 73, 158 RdKey routine 111,564 RdLCRAM 56 question mark (?) 112,193 RdMixed soft switch 157 quitting the monitor 279 RdPage2 soft switch 73,157 QWERTY keyboard 11,32 RdRAMRd soft switch 68 RdRAMWrt soft switch 68 RdText Softswitch 157 R ReadBlock all 221 RAM 339-349 Radall 233 address multiplexing 343 ReadMouse rouline 259 banks 48 Read routine 596 different machines compared 459 redirecting I/O 280 pinouts red light 14,34 accelerator ache RAM 347 INDEX 679 refreshing RAM 340 RegDsp routine 526 Save routine 600 registers, 65C02 saving machine slate code sample 637 after SmartPort call 210 schematic diagrams 406-418 changing contents 277 screen holes 66,440 displaying 523 mouse 262 examining contents 278 serial portl 181,182 restoring 599 serial port 2 189 saving 600 San routine 510 reset handler Scroll routine 556 system reset handler 78 SEGA 369 user reset handler 82 SEGB 369 Reset routine 81,524 serial data formal 184 Resets 78-79 serial I/O Init SmartPort call 230 buffer 66,471 PwrUp routine 525 different machines compared 470 Reset routine 524 serial ports. See also ACIA Reset switch 10, 31 block diagram 383 reset vector 78,82 commands 176,177,178 restart. See resets connectors 386-387 Restore routine 599 full duplex 196 retype 115 half duplex 194 RGB monitor 138 I/O 171-199 right margin 119 port 1 ROM 50,335-339 changing characteristics 182-186 different machines compared 460 characteristics 179 firmware entry points 50 data transfer 183 hardware page 52 defaults 179 pinouts firmware protocol 181 2316 ROMs 337 hardware page locations 180 23256 ROMs 336 screen holes 181,182 2364 ROMs 338 storage locations 183 signal descriptions using 172 2316 ROMs 337,338 port 2 23256 ROMs 336,337 changing characteristics 190 2364 ROMs 339 characteristics 186 versions 3 data transfer 191 routines, list of firmware 496-609 defaults 187 running a program from the Monitor 285 firmware protocol 188 680 Apple lie Technical Reference hardware page locations 188 differences from 6502 420 routing information 193 instructions 292 screen holes 189 specifications 314 using 174 liming 314 terminal mode 199 Apple lie Plus 315 ServeMouse routine 259 slots versus ports 51, 465 SetCol routine 508 Smartport 2,207,217-249 SetGr routine 531 65C02 registers 210 Setlnv routine 588 all descriptions convenlions 212 SetKbd routine 590 ailing 208 SetMouse routine 259 Ooseall 232 mode bytes 258 command number 209 SetNorm routine 589 command summary 247 SetPwrC routine 82, 535 Control all 227-229 SetTxt routine 530 device control block 228 SetVid rouline 592 device-specific calls 237-242 SetWnd routine 532 Apple 3.5 disk drive 237 Shift key 9 Download all 241 Sholes keyboard 11,32 Eject all 238,239 signals Execute all 239 ACIA 385,386 SetAddress all 240 Apple lie expansion connector 405 UniDisk 3.5 238 hand control 401 UniDiskStat 241 hand control connector 398 entry poinl 207 internal modem connector 406 error codes 248 memory expansion card connector 404 example 242 mouse button 396 extended alls 210 mouse connector 394 Format all 225 serial port generic alls 214-236 Apple lie 387 ID Type 208 Apple lie Plus 387 Init call 230 video 373 loaling 207 6502 458 Open call 231 6502A458 ReadBlock all 221 65C02 41,312-317, See also registers, 65C02, 419-131, Radall 233 addressing modes 292 Status call 215-220 block diagram 312 device information block 218 clock rate 312 device status block 216 data sheet 422 status of SmartPort driver 220 INDEX 681 unit numbers 210 GetLnZ routine 571 WriteBlock all 223 InPort routine 591 Write all 235 Keyln routine 567 soft switches 47. See also hardware addresses KeylnO routine 566 address-space selection 52 OutPort rouline 593 display modes 156-159 RdChar routine 569 display page selection 72 SetKbd routine 590 48K address space selection 67-69 SetVid routine 592 memory bank selection 63 standard input 110-115 mouse port 255 standard I/O links 108 Solid Apple key. See Option key- standard output 115-122 sound, different machines compared 467 start bit 183 sound circuit 357. See also speaker startup. See resets 83 sound jack. See audio output jack startup devices 211 SPACE parity 184 Status call 215 spaces, printing 517,518 Step command 287 Spanish keyboard 490 stepping through a program 287 speaker 135,356,358. See also audio output jack stop bit 184 circuit diagram 357 stopping a display listing 119 different machines compared 467 StorAdv routine 545 generating a tone 542,543,544, 598 Store command 273 outpul characteristics 135 Super Serial Card 172,470 output jack 358 switches. See also soft switches volume control 358 different machines compared 466 specifications, environmental 298 system interrupt handler 91 S register 42 System Monitor. See Monitor stack 53,54,93 system reset handler 78 stack pointer 42 standard entry points 124,168 standard I/O 156. See also I/O links TabV rouline 533 C3COutl routine 582 T command 195,196,198 C3KeyIn routine 567 television set 138 COut routine 581 temperature 298 COutl routine 582 terminal mode 199 COutZ routine 583 text and Lo-Res graphics Page 1 64,155 FD 10 routine 565 text and Lo-Res graphics Page IX 66 GetLn routine 572 text and Lo-Res graphics Page 2 66,155 GetLnO routine 574 text and Lo-Res graphics Page 2X 66 GetLnl routine 575 text displays 367 682 Apple lie Technical Reference displaying inverse and normal 279 U 80-column 146 underscore (_) 193 40-column 146 UniDisk 3.5 Apple He features 23-24 normal, inverse, and flashing 120,143 UniDiskStat call 241 text modes 143 unit numbers, SmartPort 210 mixed mode 154 unlocking accelerator code sample 638 lext screen Up routine 549 base address 541 USA keyboard 479 daring 534 user reset handler 82 clearing a line 557,558 user reset vector 88 initializing 529 printing a character to 545,547 scrolling 556 Validity-Check byte 80,82,535 setting 530 VBL interrupt. See vertical blanking interrupt Text soft switch 157 VDT. See video display text window 119 vectors, Page $03 80 setting 532 Verify command 276, 282 liming Verify routine 586 65C02 314 versions of Apple lie 538 RAM 344 characteristics of 3-4,456-457 timing generator. See TMG identifying which 2, 458 liming signals vertical blanking interrupt 96,469 video display 368,369 venial tab 533,550,551 TLP1 64,155 V1D circuit 373 TLP1X 66 video display 358-377. See also video output TLP2 66,155 address transformation 361 TLP2X 66 block diagram 366 TMG (timing generator) 323 connector 374 and Hi-Res graphics 372 counters 359 pinouts 323 different machines compared 468-469 signal descriptions 323 display modes 365-373 Trace command 287 address bits 363 tracing through a program 287 Double Hi-Res 152,372 transparent mode 254 Hi-Res graphics 371-373 two-key rollover 9 Lo-Res graphics 369-370 types of Apple II 458 text 367 display pages 155 expansion output 374-377 memory addressing 360 INDEX 683 NTSC 359 Z PAL 359 zero page 53 specifiations 139,140 ZIDByte 540 standard entry points 168 ZIDByte2 539 timing signals 368, 369 ZMode routine 609 video expansion connector 376-377 videomonitors 138 video output 138-171. See also video display output signals 373 video output port characteristics 139 VidOut routine 547 VidWait routine 536 VLine routine 503 voltage converter in original Apple lie 20. See also power supply voltage line 298 volume control 14,31,358 VTab routine 550 VTabz rouline 551 W Wait routine 334,559 code sample 639 warm start 88. See also resels WriteBlock all 223 Write all 235 Write routine 595 X X register 42 printing 514,515,516 Xfer routine 69-70,71-72 Y Y register 42 printing 514 684 Apple lie Technical Reference THE APPLE PUBLISHING SYSTEM This Apple manual was written, edited, and composed on a desktop publishing system using Apple Macintosh81 computers and Microsoft® Word. Proof pages were created on the Apple LaserWriter® Plus. Final pages were created on the Varilyper® VT600™. POSTSCRIPT®, the LaserWriter page-description language, was developed by Adobe Systems Incorporated. Some of the illustrations were created using Adobe Illustrator™. Text type is ITC Garamond® (a downloadable font distributed by Adobe Systems). Display type is ITC Avant Garde Gothic®. Bullets are ITC Zapf Dingbati®. Some elements, such as program listings, are set in Apple Courier, a fixed-width font. 1