Date : Wed, 27 Oct 2004 12:49:32 +0200
From : John Kortink <kortink@...>
Subject: Re: &D00
On Wed, 27 Oct 2004 11:31:54 +0100, Richard_Talbot-Watkins@...
wrote:
>Richard Gellman wrote on 27/10/2004 10:57:34:
>
>> Eep! Don't want to RTI. On BBC Micros, there is almost never a need
for
>> a user program to use RTI. The 6502 guns all NMIs through the NMI
vector
>> address at the top end of the MOS ROM. This vector points to a
location
>> in the MOS which in turn indirects through soft NMI vectors.
>
>No, RTI is correct, *particularly* for NMI handling!
>
>Upon an NMI, the 6502 looks at the address stored in the NMI vector at
>&FFFA/&FFFB. In all Beeb OS versions to my knowledge, this contains
&0D00.
>The stack is set up for returning via an RTI, i.e. the return address
>(minus 1) is pushed, followed by the processor status (P flag). There
is
>no further veneer in the OS for hooking into NMIs - NMI clients simply
copy
>their NMI handler into the memory starting at &D00 and do it all
>themselves.
Additionally, within most disc FSses at least, there's
no state at &D00 (through to D9F BBC, D5F Master), at
least not outside execution of disc operations (and
these are basically atomic), so NMI space *may* be
used if it is known that no Econet is present. It's
still best not to, and try to use the stack, or, if
you're lazy, &100 onwards, for temporary workspace.
>[...]
>
>> [1] The JSR-JMP construct is a cunning way of implementing JSR (addr).
>> The basic code runs as follows:
>>
>> Store JMP (addr) opcode (&6C):
>> LDA #&6C:STA &1000
>> Store the address:
>> LDA #LSBaddr: STA &1001
>> LDA #MSBaddr: STA &1002
>> Then JSR it:
>> JSR &1000
>>
>> The JMP jumps to the code, but the RTS will return to the address the
>> JSR was called from.
>
>Even more cunning is just to push the return address yourself, i.e.
>
>LDA #(return_addr-1)DIV256:PHA
>LDA #(return_addr-1)AND255:PHA
>JMP (whatever)
>.return_addr
>
>Then the routine at 'whatever' can exit simply via RTS.
>(maybe I've pushed that return address the wrong way round, I can't
>remember).
I think the intended order is <vectored routine> <whatever>,
not the other way around, as you have here.
John Kortink
--
Email : kortink@...
Homepage : http://www.inter.nl.net/users/J.Kortink