Code: Select all
00 BRK
14-brk
Failed
While running test 14 of 15Are there CPU test ROMs that I should run before running this one? I'm not sure if there is a particular order in which I should be trying these ROMs. Haha.
Any input is appreciated.
Moderator: Moderators
Code: Select all
00 BRK
14-brk
Failed
While running test 14 of 15Do you have verification of this claim on non-NES 6502 processors? You're going to have a hard time convincing me of that, mainly because this feature is used on the Apple II to detect the difference between a hardware and software IRQ.blargg wrote:^^^ perfect example of the confusion the "B flag exists in status register" causes (pdq, nothing specific to you; this confusion is present in almost every 6502 book and web page).
As pdq said, BRK does the following:
1. Push address of BRK instruction + 2
2. PHP
3. SEI
4. JMP ($FFFE)
Code: Select all
lda #$08
pha
plp
php
plaCode: Select all
irq_vector:
PLA
PHA
AND #%00010000
BNE IRQ_caused_by_BRKI will point out that the aforementioned book erroneously states on page 70 that the P register's bit 4 is "dedicated to determining software vs. hardware IRQ" -- as blargg has said, the P register actually doesn't use bits 5 and 4. Otherwise, everything I said above stands.The fact that the opcode for the BRK instruction is $00 is directly related to one of its uses: patching existing programs. Patching is the process of inserting instruction data in the middle of an existing program in memory to modify (usually to correct) the program without reassembling it. This is a favoured method of some programmers in debugging and testing assembly language programs, and is quite simple if you have a good machine-level monitor program that allows easy examination and modification of memory locations. However, if the program to be patched is stored in PROM (programmable read-only memory), the only way to modify a program that has already been "burned-in" is to change any remaining one bits to zeroes. Once a PROM bit has been "blown" to zero, it cannot be restored to a one. The only way to modify the flow of control is to insert BRK instructions -- all zeroes -- at the patch location and to have the BRK handling routing take control from there.
I tried to make it less convoluted this time; could you go in and fix it further?koitsu wrote:The wiki page states, in a highly convoluted way, what I've been saying and what pdq said.
This illustrates the point, but don't try it in production code. The old contents of A have been destroyed, and if the IRQ wasn't caused by BRK, the main program won't expect this.A piece of code which is pointed to by the IRQ/BRK vector (at $FFFE-FFFF) can do the following to determine a hardware IRQ vs. software IRQ (BRK):
Code: Select all
irq_vector: PLA PHA AND #%00010000 BNE IRQ_caused_by_BRK
That was interesting. Thanks.one of BRK's historic purposes is outlined in "Programming the 65816, Including the 6502, 65C02, and 65802" book by David Eyes and Ron Lichty on page 255. Quote:
As I understand it, RTI and PLP don't "clear" bit 4, that is, they don't write back to the stack. They just ignore it.Finally, I don't know about pdq's claim that RTI clears bit 4 of the status registers popped off the stack by RTI itself. The documentation I have doesn't indicate that happens, but it might.
Code: Select all
irq_vector:
sta saved_a
pla
pha
and #%00010000
bne was_brk
...