Gotchas: Difference between revisions

1,073 bytes added ,  1 year ago
m
Line 19:
 
<lang 6502asm>byte $45 ;this is the literal constant value $45, not "the value stored at memory address 0x0045"</lang>
 
 
===Memory-Mapped Hardware===
Memory-mapped hardware is a huge source of gotchas in and of itself. These hardware ports are addressed as though they were memory, but are not actually memory.
 
* Reading a port doesn't necessarily give you the last value written to it, unlike genuine RAM.
* Some ports are read-only, where some are "write-only."
* Certain instructions, such as <code>INC</code> and <code>DEC</code>, read from a value and write back to it. This can count as two accesses to a memory-mapped port (if the port cares about that, not all do.) A simple <code>LDA</code> or <code>STA</code> represents a single access.
* Generally speaking, you'll only be able to use <code>STA</code>,<code>STX</code>, or <code>STY</code> to write to ports. You'll need to read the documentation for your hardware.
 
Some examples of bad memory-mapped port I/O for various hardware:
<lang 6502asm>INC $2005 ;the intent was to scroll the NES's screen to the right one pixel. That's not gonna happen.
;What actually happens? Who knows! (I made this mistake once long ago.)</lang>
 
=={{header|68000 Assembly}}==
1,489

edits