Category:6502 Assembly: Difference between revisions

m
Line 26:
* A read-only port is what it sounds like. Attempting to write to this address will not affect the contents.
 
* A write-only port can be written to, but reading it will result in undefined behavior. The value read from the address is not necessarily what was last stored in it. Often, programmers will keep a "shadow register" in RAM containing the value intended for the port, and the port is only ever actually written to by copying from the shadow register. If the value in the port is ever needed for a calculation, the shadow register is read in its place. To make this more strange, it's even possible to have these ports in ROM as well as RAM. For example, Castlevania 3 on the Famicom updates its sound hardware by writing to sections of the cartridge ROM. Needless to say, the cartridge ROM is not altered by these writes. Attempting to read from memory-mapped ports in ROM will return whatever opcode, operand, or data is stored at that address, not the value that was last written to it.
 
* It is possible that a port that can be read, will be altered after reading it. Furthermore, writing to one port can alter the contents in another. This is often seen in video RAM ports, where writing to the port responsible for storing background graphics will auto-increment the value stored in the port responsible for deciding where those graphics will be stored. (This is how the NES's picture processing unit operates.)
1,489

edits