Trying to understand 'Vectors' in the 6502 sense

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
User avatar
Brickman
Posts: 23
Joined: Mon Oct 03, 2011 9:33 pm

Trying to understand 'Vectors' in the 6502 sense

Post by Brickman »

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:
3gengames
Formerly 65024U
Posts: 2281
Joined: Sat Mar 27, 2010 12:57 pm

Re: Trying to understand 'Vectors' in the 6502 sense

Post by 3gengames »

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. :)
User avatar
blargg
Posts: 3717
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Re: Trying to understand 'Vectors' in the 6502 sense

Post by blargg »

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.
User avatar
Movax12
Posts: 529
Joined: Sun Jan 02, 2011 11:50 am

Re: Trying to understand 'Vectors' in the 6502 sense

Post by Movax12 »

The indirect instructions works the same way: with a pointer.

Example, you could soft reset the system with jmp ($FFFC)
User avatar
Brickman
Posts: 23
Joined: Mon Oct 03, 2011 9:33 pm

Re: Trying to understand 'Vectors' in the 6502 sense

Post by Brickman »

I think i understand it now, thank you for the thorough explanations!
Post Reply