This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

BRK same as NOP in 2A03, right?

BRK same as NOP in 2A03, right?
by on (#166346)
http://www.thealmightyguru.com/Games/Hacking/Wiki/index.php?title=BRK
This is correct ? please tell me why. gentleman/lady thanks :mrgreen:
Re: BRK same as NOP in 2A03, right?
by on (#166348)
In 6502 processors, BRK ($00 xx) calls the IRQ handler once. If the IRQ handler is just RTI, then it's the same as a NOP that just takes longer to run. But games may use the IRQ handler as a crash handler or to control raster splits.

So that page is incorrect. I encourage regulars of this board to do a few things:
Re: BRK same as NOP in 2A03, right?
by on (#166353)
xuling93 wrote:

That information is completely wrong.
Re: BRK same as NOP in 2A03, right?
by on (#166357)
That BRK in Dragon Warrior 4 is probably an inline argument to the JSR before it, and not actually executed as an instruction.
Re: BRK same as NOP in 2A03, right?
by on (#166359)
AWJ wrote:
That BRK in Dragon Warrior 4 is probably an inline argument to the JSR before it, and not actually executed as an instruction.

No, it's a valid instruction. It calls the IRQ handler, if executed. (How would it be an "inline argument" to the JSR?)
Re: BRK same as NOP in 2A03, right?
by on (#166360)
Information at said page is completely incorrect. Do not heed.
Re: BRK same as NOP in 2A03, right?
by on (#166364)
rainwarrior wrote:
AWJ wrote:
That BRK in Dragon Warrior 4 is probably an inline argument to the JSR before it, and not actually executed as an instruction.

No, it's a valid instruction. It calls the IRQ handler, if executed. (How would it be an "inline argument" to the JSR?)

I think the implication was that the $00 byte at that address is never executed. Instead, it is treated as data, and the called subroutine increases the program counter on the stack to skip the data after using it. The MLI system call interface in Apple ProDOS uses the same trick: each JSR $BF00 is followed by a syscall number and a pointer to the parameter block.

But the registration information came back fairly quickly. This leaves finding test ROMs that rely on BRK not being NOP.
Re: BRK same as NOP in 2A03, right?
by on (#166367)
I saw this page last summer when I was working on an emulator, with no prior knowledge of nes programming. It confused me quite a bit.
Re: BRK same as NOP in 2A03, right?
by on (#166368)
tepples wrote:
...the called subroutine increases the program counter on the stack to skip the data after using it.

Yeah, that makes sense. I guess that's actually the most compact way to create arguments for a function.

Of course, Dragon Warrior IV is not doing that:
Code:
1F:C52F:A9 00     LDA #$00
1F:C531:85 1F     STA $001F = #$00
1F:C533:8D 0A 05  STA $050A = #$00
1F:C536:8D 0B 05  STA $050B = #$00
1F:C539:8D 08 05  STA $0508 = #$00
1F:C53C:8D 09 05  STA $0509 = #$00
1F:C53F:8D 13 05  STA $0513 = #$02
1F:C542:60        RTS


I'm don't know if those two JSRs ever get executed, they could be vestigial code, but they do indeed look like code and not data to me. (They both point to very valid looking subroutines, like the one above.) Also it certainly does use BRK elsewhere in a functional way (seems to happen when talking text is gradually appearing).
Re: BRK same as NOP in 2A03, right?
by on (#166371)
I did a bunch of Google searches, trying to identify the source of this strange / incorrect page about BRK.

All of the 6502 (or derivative) chips have functioning BRK instructions.

I think,maybe, the misinformation comes from the fact that the B flag isn't saved...
http://nesdev.com/the%20'B'%20flag%20&% ... uction.txt

And, perhaps the author felt that without a B flag, the interrupt wouldn't trigger. ?

But. It is the i flag that triggers allows an interrupt, and that flag works fine.


Edit, also...its 7 cycles for BRK and 6 for RTI...so, not even close to 2 cycle NOP.
Re: BRK same as NOP in 2A03, right?
by on (#166374)
Also...

Did anyone notice that I pointed out an error in a document on the nesdev page?
Re: BRK same as NOP in 2A03, right?
by on (#166375)
I don't know why that page still exists. There's a ton of misinformation on it. At the very least if we don't want to just get rid of it, we could shuffle all that information to a secondary page so that the nesdev.com main page primarily links to the Forum / Wiki and maybe a little less prominent link to all those legacy documents.
Re: BRK same as NOP in 2A03, right?
by on (#166382)
Hiryu no Ken Special uses BRK for inter-bank subroutine calls. Other Culture Brain games might do so as well.
Re: BRK same as NOP in 2A03, right?
by on (#166385)
I've updated the wiki page in question. Keep an eye on it to see if my change gets reverted. I need to think of a plan for the front page of nesdev.com.
Re: BRK same as NOP in 2A03, right?
by on (#166391)
tepples wrote:
This leaves finding test ROMs that rely on BRK not being NOP.

Blargg's NES CPU instruction tests contain a test a case for BRK: 15-brk
Re: BRK same as NOP in 2A03, right?
by on (#166417)
good advice! thanks, everyone.
especially tepples && rainwarrior && dougeff. to make me more deeply understand the meaning of IRQ :mrgreen:
Re: BRK same as NOP in 2A03, right?
by on (#166618)
AWJ wrote:
Hiryu no Ken Special uses BRK for inter-bank subroutine calls.

:O my mind was just blown by this idea.
Re: BRK same as NOP in 2A03, right?
by on (#166631)
That's a common use for the RST opcodes on the dmg-z80 too.
Re: BRK same as NOP in 2A03, right?
by on (#166633)
thenewguy wrote:
AWJ wrote:
Hiryu no Ken Special uses BRK for inter-bank subroutine calls.

:O my mind was just blown by this idea.

In my own game I've used it for a diagnostic blue screen of death.