How do I set up MMC3?

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

Moderator: Moderators

User avatar
Posts: 4218
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: How do I set up MMC3?

Post by koitsu » Thu Sep 20, 2018 12:26 pm

sdm wrote:ok, everything seems to work, the problem was a small trifle - before LDA% 00000110, there was no "#" character (of course, nesasm3 did not display an error and I missed the problem).
Just a comment in passing, and isn't intended to disparage or chastise you! It's more about "assembler education":

If the code was lda %00000110, then that's 100% valid code; the assembler not showing an error is correct behaviour. What you did there is essentially the same as writing lda 6 or lda $06 (load accumulator from zero page location 6). Just because you chose to use base 2 (binary) instead of base 10 (decimal) or base 16 (hexadecimal) doesn't change things in the least. There's no 100% correct way for the assembler to detect this situation as an error vs. something the user actually wanted to do; you can't assume that using base 2 as an operand isn't what the user wanted to do, and I have seen plenty of code on the Apple II where people have used base 10 addresses as operands, as "bizarre" as that might seem, but it's perfectly OK.

Iplementing a feature in the assembler (defaulting to disabled) that would allow you to tell it "only expect labels/equates, or base 16 numbers, as operands for non-immediate addressing modes" might sound like a good idea, right? When enabled, lda %00000110, lda 6, or MYVAL = %00000110 / lda MYVAL would cause an error to be thrown, while lda $06 or MYVAL = $06 / lda MYVAL would be OK. This would be annoying to implement in the assembler, however, because it would then have to track what base a particular line of code used, and there's no way to sanely deal with, say, lda $06+%10000000 (e.g. lda $86) or MYVAL = $06 + 128 / lda MYVAL. In other words, there would be tons of edge-case situations that would cause the assembler to potentially throw an error when the user didn't want it, plus adding complexity. Starting to see why nobody tries to implement this kind of thing? :-)

Like with any programming language, a single character/byte mistake can cause lots of pain. Pain that can cost you hours of time debugging/reverse-engineering. It's not unique to 6502 assembly at all. There isn't a 100% infallible way to relieve this problem in the computing world, sorry to say.

Posts: 306
Joined: Tue Apr 11, 2006 4:08 am
Location: Poland

Re: How do I set up MMC3?

Post by sdm » Mon Oct 01, 2018 2:56 am

How many cpu cycles does the switching of mmc3 bank take? it's about 0 8000-9fff bank changed into another one:

Code: Select all

	LDA #%00000110	;6 / 8000-9fff
	STA $8000
	LDA #2		;switch to mmc3 bank 2
	STA $8001

Posts: 22143
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)

Re: How do I set up MMC3?

Post by tepples » Mon Oct 01, 2018 7:01 am

That's 12 cycles: load immediate is 2, and store absolute is 4. The new bank is visible as soon as the STA instruction's memory access cycle completes, which is before the next instruction gets fetched.

Post Reply