Category:6502 Assembly: Difference between revisions

m
Line 31:
 
* 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, such as checking which video mode is currently active, the shadow register is read for the purposes of that calculation.
 
 
* A port can be in ROM as well as RAM. Ports whose address is located in ROM are always write-only. 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 reading a port will alter its contents, or alter the contents of other related ports. This includes both <code>LDA/LDX/LDY</code> and other commands that need to read the contents of the address in order to execute, such as <code>BIT</code>,<code>LSR</code>,etc.
 
 
* Writing to ports with commands other than <code>LDA/LDX/LDY</code> can sometimes fail or result in undefined behavior. For example, <code>INC</code> or <code>DEC</code> may not have the desired result.
1,489

edits