Trying to understand 'Vectors' in the 6502 sense

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Trying to understand 'Vectors' in the 6502 sense
by on (#101967)
I'm having trouble exactly understanding what 'vector' means in nes asm/6502 terminology.
Is the vector for an IRQ like a pointer?

Is it closer to this?
http://en.wikipedia.org/wiki/Interrupt_vector

Or this?
http://en.wikipedia.org/wiki/Vectored_Interrupt

I thank you for your time. :mrgreen:
Re: Trying to understand 'Vectors' in the 6502 sense
by on (#101968)
Vectors are areas to tell the computer where the program for something starts. There's the Reset, IRQ, and NMI vectors. When the machine is reset, it looks at the (little endian value) reset location and then starts running program from there. Same with IRQ and NMI, when those happen, it just tells it where to run the program when those things happen. :)
Re: Trying to understand 'Vectors' in the 6502 sense
by on (#101969)
Yes, a vector is a pointer to the code that handles the respective interrupt. There are three pointers, stored at the top 6 bytes of memory ($FFFA-$FFFF). This scheme is in contrast to some processors that jump to fixed locations in memory where the code must reside, e.g. $0000 for reset, $0010 for NMI, etc. The difference is minor, since the latter can just put a JMP instruction there, and treat its address as a pointer like the NES uses.

As for being fully vectored, the NES actually uses a hybrid scheme, where the main three causes of interrupts (reset, NMI, IRQ) are separately vectored to different code, but then the causes of IRQ must be polled: BRK instruction, and if IRQ, which device caused it if there are multiple causes (APU, cartridge's mapper, which may have multiple sources). Polling just means that the interrupt handling code must ask each hardware device whether it was the cause of the IRQ, and then acknowledge it so it won't generate it again. Clearly this is slower than if the processor vectors each possible cause to a different code handler.
Re: Trying to understand 'Vectors' in the 6502 sense
by on (#101995)
The indirect instructions works the same way: with a pointer.

Example, you could soft reset the system with jmp ($FFFC)
Re: Trying to understand 'Vectors' in the 6502 sense
by on (#101999)
I think i understand it now, thank you for the thorough explanations!