User:Zzo38/6502 programming tricks: Difference between revisions
From NESdev Wiki
Jump to navigationJump to search
No edit summary |
No edit summary |
||
Line 41: | Line 41: | ||
Note: This should be done itself inside of a subroutine which finally does the same effect as another, so it still needs to be called. | Note: This should be done itself inside of a subroutine which finally does the same effect as another, so it still needs to be called. | ||
== Compressed data in CHR ROM == | == Compressed data in CHR ROM == | ||
Line 54: | Line 51: | ||
== See also == | == See also == | ||
* [[ | * [[Synthetic instructions]] | ||
* [[Programming with unofficial opcodes]] |
Revision as of 18:00, 23 January 2014
Toggle the zero flag
PHP PLA AND #2
- Bytes: 4
- Cycles: 9
Main-effect:
- Zero flag: toggled.
Side-effect:
- Accumulator: set to 0 or 2.
- Negative flag: cleared.
Rotate accumulator left 8-bits
ASL A ADC #0
- Bytes: 3
- Cycles: 4
Main-effect:
- Accumulator: shifted left, with shifted-out bit shifted-in.
Side-effect:
- Carry flag: cleared.
Signed compare
Do this by toggling the high bit of both numbers before comparison. For example, if 8-bit numbers:
EOR #$80
RTS trick
See RTS Trick.
Tail recursion
- Bytes: -1
- Cycles: -9
This can be done by replacing a JSR/RTS with just a JMP, since the subroutine it jumps to will have its own RTS.
Fall-through tail recursion
- Bytes: -4
- Cycles: -12
Instead of jumping to another subroutine, you can just fall-through into it. In fact you can even JSR to it and then fall through to it (possibly doing something else in between if wanted), if you want to run it twice; Super Mario Bros. uses this pattern.
Note: This should be done itself inside of a subroutine which finally does the same effect as another, so it still needs to be called.
Compressed data in CHR ROM
(TODO)
Storing high byte and low byte of an address in separate tables
(TODO)