Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/17/84; site uvicctr.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!vax135!cornell!uw-beaver!ssc-vax!uvicctr!collinge
From: collinge@uvicctr.UUCP (Doug Collinge)
Newsgroups: net.micro.apple
Subject: Re: Interupts on a apple ][+
Message-ID: <157@uvicctr.UUCP>
Date: Wed, 6-Nov-85 12:59:22 EST
Article-I.D.: uvicctr.157
Posted: Wed Nov  6 12:59:22 1985
Date-Received: Sun, 10-Nov-85 07:34:29 EST
References: <76@noscvax.UUCP> <829@psivax.UUCP>
Reply-To: collinge@uvicctr.UUCP (Doug Collinge)
Organization: University of Victoria, Victoria B.C. Canada
Lines: 46
Keywords: Apple II interrupts
Summary: 

>In article <76@noscvax.UUCP> medin@nosc (Ted Medin) writes:
>>Specifically when I get an interupt the areg is
>>always an 8 or 18 hex. This makes it very difficult to return to the 
>>interupted code with the regs restored. 

In article <829@psivax.UUCP> tommie@psivax.UUCP (Tom Levin) writes:
>NO REGISTERS ARE SAVED FOR YOU!!!  Yes, you must
>save all of the registers yourself and restore them after the "rti"
>(return from interrupt) command.  I don't consider this an architecture
>failure.

One more time, and one more time only...

The Apple ROM kindly decodes break instructions from IRQ interrupts for
you.  In the process it has to wreck the Areg.  Since it is going to
store all registers in hardcoded locations anyway if it was a BRK it
saves the Areg in location $45 before wrecking it.  Therefore the
minimum Apple interrupt handler is:
	IRQ	=	*
		LDA	$45
		RTI
If you want to save regs:
		LDA	$45
		PHA
		TYA
		PHA
		TXA
		PHA
	* Do what you will here.
		PLA
		TAX
		PLA
		TAY
		PLA
		RTI
Pushing the Areg on the stack is necessary if you want a reentrant interrupt
handler.

-- 
		Doug Collinge
		School of Music, University of Victoria,
		PO Box 1700, Victoria, B.C.,
		Canada,  V8W 2Y2  
		decvax!nrl-css!uvicctr!collinge
		decvax!uw-beaver!uvicctr!collinge
		ubc-vision!uvicctr!collinge