UNROM bus conflict handling
Moderator: Moderators
UNROM bus conflict handling
The wiki article on this particular mapper states "The original UxROM boards used by Nintendo were subject to bus conflicts, and the relevant games all work around this in software.", so I was curious about how is this usually done and what would be a good and reliable way to implement it? And now that we are on the subject; does bank swapping take a certain amount of cycles before it's been swapped successfully or is it instant?
Avatar is pixel art of Noah Prime from Astral Chain
- rainwarrior
- Posts: 8732
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: UNROM bus conflict handling
A very common way is to have a table of numbers from 0 to 15, or however many banks you have, and do an indexed store on top of that table so the 2 numbers match (eliminating the conflict issue).
It's effectively instant. The bank will be ready before the next instruction is fetched,
Code: Select all
LDA #bank
TAX
STA table, X
table: .byte 0,1,2,3,4,5,6,7...
Re: UNROM bus conflict handling
See also replies to casprog's recent question about the same issue on a different discrete mapper.
Re: UNROM bus conflict handling
Seems simple enough. Thanksrainwarrior wrote:A very common way is to have a table of numbers from 0 to 15, or however many banks you have, and do an indexed store on top of that table so the 2 numbers match (eliminating the conflict issue).It's effectively instant. The bank will be ready before the next instruction is fetched,Code: Select all
LDA #bank TAX STA table, X table: .byte 0,1,2,3,4,5,6,7...
By the way is there an actual explanation on why doing this eliminates the conflict and what issues you could run into if you don't handle the bus conflict, for both PRG and CHR (although UNROM doesn't have these) if the issues differ?
Avatar is pixel art of Noah Prime from Astral Chain
Re: UNROM bus conflict handling
The wrong bank may be selected, depending on the specific values you write and in ROMSusiKette wrote:what issues you could run into if you don't handle the bus conflict
Re: UNROM bus conflict handling
Yes, there is an entire wiki page on the subject. The explanation requires understanding of how actual hardware works: https://wiki.nesdev.com/w/index.php/Bus_conflictSusiKette wrote:By the way is there an actual explanation on why doing this eliminates the conflict ...
- rainwarrior
- Posts: 8732
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: UNROM bus conflict handling
The bus conflict occurs because the ROM isn't disabled by the write signal (saves some wiring to have it enabled only by PRG A15, i.e. when the address is >= $8000), so at the moment of the write you have your storing value from the CPU on the bus, but also the value output from the ROM.SusiKette wrote:By the way is there an actual explanation on why doing this eliminates the conflict and what issues you could run into if you don't handle the bus conflict, for both PRG and CHR (although UNROM doesn't have these) if the issues differ?
With two signals on the bus like this, one or the other "wins" or some other behaviour occurs depending on properties of their circuits. If both are the same, though, it doesn't matter which one wins, because both have the correct value.
That value goes from the bus to a latch on the chip that controls the banking.
You can have bus conflicts with either PRG or CHR banking, it doesn't matter what you're banking though, it matters where the register you're writing to is. If the register is at $8000-FFFF, that overlaps with PRG. (I think theoretically you could have a bus conflict with CHR while writing through $2007, but this is a bit obscure, mapper registers are usually in CPU space not PPU.)
They basically did this because it saves one extra component to disable the PRG-ROM during writes. With ASIC mappers it was easier to add the extra logic, so they typically don't have bus conflict problems.
Last edited by rainwarrior on Mon Oct 08, 2018 12:31 pm, edited 1 time in total.
Re: UNROM bus conflict handling
The conflict happens because the CPU is outputting a value at the same time as the ROM chip, both going to the same wires. If the values are different, there's a conflict.SusiKette wrote:By the way is there an actual explanation on why doing this eliminates the conflict
The two values on the bus are combined in some way that depends on the type of memory chip used, and an unpredictable value ends up being sent to the mapper, which results in the wrong banks being selected.and what issues you could run into if you don't handle the bus conflict, for both PRG and CHR (although UNROM doesn't have these) if the issues differ?
I also heard that there may be electrical issues resulting from shorting 1s (+5V) and 0s (GND), like the chips heating up or something, but I don't know if that's true or if it could cause any permanent damage to the hardware.
Re: UNROM bus conflict handling
Sorry to nickpick but this piece of code is actually "wrong". Well it'll work but waste time/bytes. It's eitherrainwarrior wrote:A very common way is to have a table of numbers from 0 to 15, or however many banks you have, and do an indexed store on top of that table so the 2 numbers match (eliminating the conflict issue).Code: Select all
LDA #bank TAX STA table, X table: .byte 0,1,2,3,4,5,6,7...
Code: Select all
LDA #bank
STA table+bank
Code: Select all
LDA bank ; Or any other piece of code computing the bank and having the result in A
TAX
STA table, X
If no variable bank is ever switched, then it can be simplified down to
Code: Select all
changebank:
LDA #bank
STA changebank+1
In classic UNROM (128kb PRG-ROM) you'll hardly ever select bank 7 as it is always swapped in $c000-$ffff, so you can take this into account and have the "table" hold the values 0-6 only.
- rainwarrior
- Posts: 8732
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: UNROM bus conflict handling
Sure. I was merely trying to illustrate the table technique. the LDA immediate was really just a placeholder. I think most of those more specific techniques are covered on the bus conflict wiki page that koitsu linked, though maybe there's some more in there worth adding.