BRK same as NOP in 2A03, right?

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

User avatar
xuling93
Posts: 7
Joined: Mon Apr 13, 2015 7:52 am

BRK same as NOP in 2A03, right?

Post by xuling93 »

http://www.thealmightyguru.com/Games/Ha ... ?title=BRK
This is correct ? please tell me why. gentleman/lady thanks :mrgreen:
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: BRK same as NOP in 2A03, right?

Post by tepples »

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:
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: BRK same as NOP in 2A03, right?

Post by tokumaru »

That information is completely wrong.
AWJ
Posts: 433
Joined: Mon Nov 10, 2008 3:09 pm

Re: BRK same as NOP in 2A03, right?

Post by AWJ »

That BRK in Dragon Warrior 4 is probably an inline argument to the JSR before it, and not actually executed as an instruction.
User avatar
rainwarrior
Posts: 8062
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: BRK same as NOP in 2A03, right?

Post by rainwarrior »

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?)
Last edited by rainwarrior on Fri Mar 18, 2016 11:45 am, edited 1 time in total.
User avatar
koitsu
Posts: 4203
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: BRK same as NOP in 2A03, right?

Post by koitsu »

Information at said page is completely incorrect. Do not heed.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: BRK same as NOP in 2A03, right?

Post by tepples »

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.
russellsprouts
Posts: 53
Joined: Sun Jan 31, 2016 9:55 pm

Re: BRK same as NOP in 2A03, right?

Post by russellsprouts »

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.
User avatar
rainwarrior
Posts: 8062
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: BRK same as NOP in 2A03, right?

Post by rainwarrior »

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: Select all

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).
User avatar
dougeff
Posts: 2875
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: BRK same as NOP in 2A03, right?

Post by dougeff »

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.
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
dougeff
Posts: 2875
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: BRK same as NOP in 2A03, right?

Post by dougeff »

Also...

Did anyone notice that I pointed out an error in a document on the nesdev page?
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
rainwarrior
Posts: 8062
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: BRK same as NOP in 2A03, right?

Post by rainwarrior »

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.
AWJ
Posts: 433
Joined: Mon Nov 10, 2008 3:09 pm

Re: BRK same as NOP in 2A03, right?

Post by AWJ »

Hiryu no Ken Special uses BRK for inter-bank subroutine calls. Other Culture Brain games might do so as well.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: BRK same as NOP in 2A03, right?

Post by tepples »

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.
User avatar
thefox
Posts: 3139
Joined: Mon Jan 03, 2005 10:36 am
Location: Tampere, Finland
Contact:

Re: BRK same as NOP in 2A03, right?

Post by thefox »

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
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
Post Reply