- yes, in NMOS 6502s, including Ricoh's 2A03, the stack pointer, together with A, X and Y, are indeterminate at power on.
Ah! Thank you for this. This hadn't turned up in my own searches, and I'd certainly have been pulling my hair out--what little I have left, anyway!--if I'd built the thing and run into this.
The ISR should end by falling through into the wait loop -- not jumping to it. Then the code can easily fit in 8 bytes. The trick is in mapping it so you get RST and NMI vectors that work. Luckily only 3 bits out of each 16-bit vector have any significance -- in context as a vector, I mean. And that gives some freedom to the other context, when those same bytes are interpreted as code. (I'm thinkin we don't need the IRQ/BRK vector, 'cause we'll use a JMP abs instead of BRK.)
The "falling through" approach was one of the first I'd entertained, but I guess my devil's hat wasn't firmly in place back then. Here's one 8-byte solution, although I'm not happy about the cycles wasted on the TXA. I'll think on this some more and see if I can find a better one (that doesn't need an extra instruction). I'm also back to 15 diodes, so hmmm... Which kind of contortionist am I trying to be?

(STA could be STX if TXA was replaced with CLC or some other no-oppish thing, but that feels somehow worse. I guess, if I just let go of the diode count, I may as well use a NOP...)
Code: Select all
$xxx0: $xx (flip-flop)
$xxx1: $40
$xxx2: $4C (JMP absolute)
$xxx3: $02
$xxx4: $A2 (LDX immediate)
$xxx5: $xx (flip-flop)
$xxx6: $8A (TXA)
$xxx7: $8D (STA absolute)
This solution is entertaining in large part because the low byte of the reset vector is also the first instruction of the NMI ISR, and the low byte of the NMI vector is also the first instruction executed on reset! Who'd have thought you could have "spaghetti code" with only eight bytes?
EDIT: And an 8-byte version with 12 diodes. Uses a throwaway ASL as a no-op. This is pleasing because, as a reset vector, in has the same effective value as LDX, so the LDX and STA can become LDY/STY. I'll probably settle here for now. My brain is tired, and at this point the functionality of the thing is pretty well nailed, I think!
Code: Select all
$xxx0: $xx (flip-flop)
$xxx1: $40
$xxx2: $4C (JMP absolute)
$xxx3: $02
$xxx4: $0A ASL ; as a NOP
$xxx5: $A0 LDY
$xxx6: $xx (flip-flop)
$xxx7: $8C STY