!pr0
DOS Patches to Avoid Interrupt Trouble..............Bill Morgan

As we reported a couple of years ago (V2N4, Jan 82), there is a serious problem in using interrupts in the Apple.  The Monitor's IRQ interrupt handler uses location $45 to store the contents of the A-register while it is checking to see if the interrupt was from IRQ, or from a BRK instruction.  Unfortunately, DOS 3.3 uses $45 for temporary storage in several different routines.  If an IRQ interrupt occurs while DOS is active, the Monitor clobbers $45 and DOS can lose a variable.

The usual solution has been to change the Monitor to use some other address to stash the Accumulator.  This can be done by copying the Monitor into the RAM card and patching in the new address, or by burning a new Monitor in EPROM and modifying the Apple to accept the chip.  The byte that needs changing is at $FA41 in the Autostart ROM, or $FA87 in the Old Monitor ROM.

In the January 84 issue of Washington Apple Pi, Bruce Field reports about the other approach to resolving the conflict.  He passes along Wilton Helm's details of the locations in DOS that refer to $45, and how to change things around to safely use interrupts without affecting anything else.  Here's Helm's report:

!lm+3
!rm-3
"Location $45 is used at the following places in DOS 3.3:

$A133 $A13E $A158 $A1BE $A1D3 $A1E8 $A1F7 $A1F9 $A201 $A2CC $A767 $A77F $ADBA $AE0A $AE54 $AE58 $BED3 $BF16 $BF39 $BF55 $BF57 $BF5B $BF9D $BFA3 $BFA5.

These locations should be changed to $46.  Location $46 is used for only one purpose, at $BA06 and at $BDA4.  These two locations should be changed to $2C.  Location $2C is used only by RWTS subroutines and does not conflict with this additional use.  The end result is that DOS no longer uses $45 and does not use any new locations."
!rm+3
!lm-3

Field also reports that "these modifications have been made in Universal DOS ... and similar patches have been made in Diversi-DOS."

Bob S-C put together the following Applesoft program to install the patches.  The program first checks to make sure that the DOS in memory has not had the patches applied already, then puts them in place.  The check beforehand will also avoid clobbering a non-standard DOS.


100  REM PREPARE DOS 3.3 FOR INTERRUPTS
110  READ A: IF A = 0 THEN 200
120  IF  PEEK (A) = 69 THEN 110
130  PRINT "THIS DOS IS ALREADY PATCHED": END 
140 I = I + 2: GOTO 120
200  READ A: IF A = 0 THEN 300
210  IF  PEEK (A) = 70 THEN 200
220  PRINT "THIS DOS IS ALREADY PATCHED": END 
300  RESTORE 
310  READ A: IF A <  > 0 THEN  POKE A,70: GOTO 310
320  READ A: IF A <  > 0 THEN  POKE A,44: GOTO 320
330  END 
1000  DATA  41267,41278,41304,41406,41427,41448,41463,41465,
     41473,41676,42855,42879,44474,44554,44628,44632,48851,
     48918,48953,48981,48983,48987,49053,49059,49061,0
1010  DATA  47622,48548,0


While we're on the subject of interrupts, I'd like to recommend a book to you:  "Real Time Programming - Neglected Topics", by Caxton C. Foster.  (Addison-Wesley, 1981.  Paperback, $8.95 a couple of years ago.)  Foster covers interrupts, ports, timing considerations, A/D conversion, filters, control loops, and communication issues.  He points out that these are "enough topics to make up the better part of a full-fledged masters program in electrical engineering or computer science" and that "no book less than 10 inches thick could cover all these topics in detail."  Nevertheless, in about 180 pages he does an excellent job of introducing the reader to the material, covering both hardware and software.
