Reputation: 147
I've been trying to understand how an old 6502 processor works, in particular for a Nintendo Entertainment System. One thing that continues to confuse me is how the system moves relevant data from the ROM into RAM, as all the assembly instructions seem to deal with RAM-RAM commands. For example, if the game needed to load an enemy in Mario, how does the CPU identify the relevant areas to load, and then loads them? Once it's in RAM I have a decent understanding, but it's getting the data into RAM that I don't understand. Thanks!
Upvotes: 3
Views: 2415
Reputation: 2761
The CPU does not know about RAM/ROM, all it knows is the bus. On one level, the bus is a collection of bits and on another it is simply a series of wires which carry a signal which is high or low. Conceptually, there are 16 wires on the address bus, 8 on the data bus and a read/write line to specify the direction. To read a value, it sets the lines on the address bus to the address to be read, sets the direction line to read and (at the appropriate clock cycle when the voltages have stabilised) takes the value off the data bus. Writing is the reverse. Attempting to write to a memory location that is mapped to ROM simply means that when the value is placed on the data bus, nothing is listening.
Some architectures have switchable memory banks which means that the write signal ends up at a RAM chip while the read signals go to ROM but the CPU is unaware of any of this. What (if anything) is listening to the bus is too far removed.
Upvotes: 2
Reputation: 334
The 6502 instructions operate on a memory bus that has 16-bit addressing. This means that it can address a memory space that goes from 0 to 65535.
In a real world 6502-based system, the RAM (random access memory) is likely going to be mapped to only a portion of that memory space, and a different portion will be mapped to the ROM (read-only memory).
Let's imagine that in our system, we have RAM
mapped to the memory space from $0000-0FFF
and we have our ROM
mapped to the memory space from $1000-1FFF
.
Loading a value from ROM into RAM would be as simple as:
LDA $1000 ; Take value from first address of ROM, put it in A register
STA $0000 ; Take value from A register, put into first address of RAM
Note: In most systems you'll also have additional hardware mapped to other segments of that space.
Upvotes: 2
Reputation: 51
I can't say that I fully understand your question, but the following may help point you in the right direction.
You need to understand the memory map of the system. A Google search for 'Nintendo Entertainment System memory map' found this helpful looking page amongst many others. https://fms.komkon.org/EMUL8/NES.html It will help you identify which areas are RAM and ROM. Somewhere in your program there must be a command that loads data from the cartridge ROM.
There is no such thing as a RAM-RAM command per se. The addressing modes are described here: http://www.emulator101.com/6502-addressing-modes.html . All data is moved via a register, so to move a byte from ROM (say $C042) to RAM (say $00F5) might look something like:
LDA $C042
STA $00F5
To be moving a whole shape definition they are likely to be using the more complex addressing mode, Absolute Indexed, or even Indexed Indirect. The latter may be what is confusing you, since the load instruction will be referencing a RAM address which has been previously loaded with the ROM address that stores the data being fetched.
It is up to the program (or rather the programmer) to keep track of where the appropriate data is loaded from and where it has to be stored.
Upvotes: 4
Reputation: 92976
In typical 6502 systems, ROM is mapped into the processor's address space. Depending on what address the processor tries to access, the access goes to RAM, ROM, nothing, or possibly something else like control register. There is typically some logic on the mainboard that looks at the high address bits and enabled the chip select line of the corresponding RAM or ROM chip. The processor cannot tell the difference, attempts to write to ROM are silently ignored.
Upvotes: 9