Fixed cycle delay: Difference between revisions
From NESdev Wiki
Jump to navigationJump to search
(Let's test a rewriting of the page.) |
(Another reformatting) |
||
Line 11: | Line 11: | ||
* @rts15 means you know a memory address that contains a <code>JMP</code> that jumps to another location that contains <code>RTS</code>. | * @rts15 means you know a memory address that contains a <code>JMP</code> that jumps to another location that contains <code>RTS</code>. | ||
* Alternatively, @rts15 means you know a memory address that contains a harmless 3-cycle instruction that fits your constraints (such as <code>LDA $00</code>), followed by <code>RTS</code>. | * Alternatively, @rts15 means you know a memory address that contains a harmless 3-cycle instruction that fits your constraints (such as <code>LDA $00</code>), followed by <code>RTS</code>. | ||
* @A, @X, @Y are local labels. | |||
=== 2 cycles === | === 2 cycles === | ||
== | {| class="wikitable" | ||
<pre>NOP</pre> | !colspan="2"|1 bytes | ||
|- | |||
|<pre>NOP</pre> | |||
|Clobbers nothing, requires nothing | |||
|- | |||
|} | |||
=== 3 cycles === | === 3 cycles === | ||
== | {| class="wikitable" | ||
!colspan="2"|1 bytes | |||
<pre>PHA</pre> | |- | ||
|<pre>PHA</pre> | |||
= | |Clobbers S | ||
|- | |||
<pre>LDA $00</pre> | !colspan="2"|2 bytes | ||
|- | |||
|<pre>LDA $00</pre> | |||
<pre>BIT $00</pre> | |Clobbers Z, N and A | ||
|- | |||
|<pre>BIT $00</pre> | |||
<pre>STA @zptemp</pre> | |Clobbers Z, N and V | ||
|- | |||
|<pre>STA @zptemp</pre> | |||
<pre>NOP $00</pre> | |Requires @zptemp | ||
|- | |||
= | |<pre>NOP $00</pre> | ||
<pre>JMP *+3</pre> | |Requires support for unofficial opcodes | ||
|- | |||
!colspan="2"|3 bytes | |||
|- | |||
|<pre>JMP *+3</pre> | |||
|Clobbers nothing, requires nothing | |||
|- | |||
|} | |||
=== 4 cycles === | === 4 cycles === | ||
== | {| class="wikitable" | ||
!colspan="2"|1 bytes | |||
<pre> | |- | ||
|<pre>PLA</pre> | |||
|Clobbers Z, N, A and S | |||
|- | |||
!colspan="2"|2 bytes | |||
|- | |||
|<pre>NOP | |||
NOP</pre> | |||
|Clobbers nothing, requires nothing | |||
|- | |||
|} | |||
=== 5 cycles === | === 5 cycles === | ||
==== | {| class="wikitable" | ||
!colspan="2"|2 bytes | |||
|- | |||
|<pre>NOP | |||
PHA</pre> | |||
|Clobbers S | |||
|- | |||
!colspan="2"|3 bytes | |||
|- | |||
|<pre>NOP | |||
LDA $00</pre> | |||
|Clobbers Z, N and A | |||
|- | |||
|<pre>NOP | |||
BIT $00</pre> | |||
|Clobbers Z, N and V | |||
|- | |||
|<pre>NOP | |||
STA @zptemp</pre> | |||
|Requires @zptemp | |||
|- | |||
|<pre>NOP | |||
NOP $00</pre> | |||
|Requires support for unofficial opcodes | |||
|- | |||
!colspan="2"|4 bytes | |||
|- | |||
|<pre>NOP | |||
JMP *+3</pre> | |||
|Clobbers nothing, requires nothing | |||
|- | |||
|} | |||
=== 6 cycles === | === 6 cycles === | ||
== | {| class="wikitable" | ||
!colspan="2"|2 bytes | |||
<pre>PHA | |- | ||
|<pre>PHA | |||
PHA</pre> | PHA</pre> | ||
|Clobbers S | |||
= | |- | ||
!colspan="2"|3 bytes | |||
|- | |||
|<pre>NOP | |||
NOP | |||
NOP</pre> | |||
|Clobbers nothing, requires nothing | |||
|- | |||
|} | |||
=== 7 cycles === | === 7 cycles === | ||
== | {| class="wikitable" | ||
<pre>PHP | !colspan="2"|2 bytes | ||
|- | |||
|<pre>PHP | |||
PLP</pre> | PLP</pre> | ||
|Clobbers nothing, requires nothing | |||
|- | |||
|} | |||
=== 8 cycles === | === 8 cycles === | ||
== | {| class="wikitable" | ||
!colspan="2"|2 bytes | |||
<pre>PLA | |- | ||
|<pre>PLA | |||
PLA</pre> | PLA</pre> | ||
|Clobbers Z, N, A and S | |||
|- | |||
!colspan="2"|3 bytes | |||
<pre>TSX | |- | ||
|<pre>TSX | |||
PLA | PLA | ||
TXS</pre> | TXS</pre> | ||
|Clobbers Z, N, A and X | |||
= | |- | ||
|<pre>NOP | |||
PHA | |||
PHA</pre> | |||
|Clobbers S | |||
|- | |||
!colspan="2"|4 bytes | |||
|- | |||
|<pre>NOP | |||
NOP | |||
NOP | |||
NOP</pre> | |||
|Clobbers nothing, requires nothing | |||
|- | |||
|} | |||
=== 9 cycles === | === 9 cycles === | ||
== | {| class="wikitable" | ||
!colspan="2"|3 bytes | |||
|- | |||
|<pre>NOP | |||
PHP | |||
PLP</pre> | |||
|Clobbers nothing, requires nothing | |||
|- | |||
|} | |||
=== 10 cycles === | === 10 cycles === | ||
== | {| class="wikitable" | ||
!colspan="2"|3 bytes | |||
<pre>PHA | |- | ||
|<pre>PHA | |||
PHP | PHP | ||
PLP</pre> | PLP</pre> | ||
|Clobbers S | |||
= | |- | ||
!colspan="2"|4 bytes | |||
<pre>PHP | |- | ||
|<pre>PHP | |||
BIT $00 | BIT $00 | ||
PLP</pre> | PLP</pre> | ||
|Clobbers nothing, requires nothing | |||
|- | |||
|} | |||
=== 11 cycles === | === 11 cycles === | ||
== | {| class="wikitable" | ||
!colspan="2"|3 bytes | |||
<pre>PHA | |- | ||
|<pre>PHA | |||
PLA | PLA | ||
PLA</pre> | PLA</pre> | ||
|Clobbers Z, N, A and S | |||
= | |- | ||
!colspan="2"|4 bytes | |||
|- | |||
|<pre>NOP | |||
NOP | |||
PHP | |||
PLP</pre> | |||
|Clobbers nothing, requires nothing | |||
|- | |||
|} | |||
=== 12 cycles === | === 12 cycles === | ||
== | {| class="wikitable" | ||
!colspan="2"|3 bytes | |||
<pre>JSR @rts12</pre> | |- | ||
|<pre>JSR @rts12</pre> | |||
|Requires @rts12 | |||
<pre>PLA | |- | ||
|<pre>PLA | |||
PLA | PLA | ||
PLA</pre> | PLA</pre> | ||
|Clobbers Z, N, A and S | |||
= | |- | ||
!colspan="2"|4 bytes | |||
<pre>ROL $00,X | |- | ||
|<pre>ROL $00,X | |||
ROR $00,X</pre> | ROR $00,X</pre> | ||
|Clobbers Z and N | |||
= | |- | ||
|<pre>NOP | |||
PHA | |||
PHP | |||
PLP</pre> | |||
|Clobbers S | |||
|- | |||
!colspan="2"|5 bytes | |||
|- | |||
|<pre>NOP | |||
PHP | |||
BIT $00 | |||
PLP</pre> | |||
|Clobbers nothing, requires nothing | |||
|- | |||
|} | |||
=== 13 cycles === | === 13 cycles === | ||
== | {| class="wikitable" | ||
!colspan="2"|4 bytes | |||
<pre>PHA | |- | ||
|<pre>PHA | |||
PHA | PHA | ||
PHP | PHP | ||
PLP</pre> | PLP</pre> | ||
|Clobbers S | |||
= | |- | ||
!colspan="2"|5 bytes | |||
|- | |||
|<pre>NOP | |||
NOP | |||
NOP | |||
PHP | |||
PLP</pre> | |||
|Clobbers nothing, requires nothing | |||
|- | |||
|} | |||
=== 14 cycles === | === 14 cycles === | ||
== | {| class="wikitable" | ||
!colspan="2"|3 bytes | |||
<pre>JSR @rts14</pre> | |- | ||
|<pre>JSR @rts14</pre> | |||
= | |Requires @rts14 | ||
|- | |||
!colspan="2"|4 bytes | |||
|- | |||
|<pre>PHP | |||
PLP | |||
PHP | |||
PLP</pre> | |||
|Clobbers nothing, requires nothing | |||
|- | |||
|} | |||
=== 15 cycles === | === 15 cycles === | ||
== | {| class="wikitable" | ||
!colspan="2"|3 bytes | |||
<pre>JSR @rts15</pre> | |- | ||
|<pre>JSR @rts15</pre> | |||
= | |Requires @rts15 | ||
|- | |||
<pre>PHA | !colspan="2"|4 bytes | ||
|- | |||
|<pre>PHA | |||
JSR @rts12</pre> | JSR @rts12</pre> | ||
|Clobbers S and requires @rts12 | |||
|- | |||
<pre>PHA | |<pre>PHA | ||
PLA | PLA | ||
PLA | PLA | ||
PLA</pre> | PLA</pre> | ||
|Clobbers Z, N, A and S | |||
= | |- | ||
!colspan="2"|5 bytes | |||
<pre>LDA $00 | |- | ||
|<pre>LDA $00 | |||
JSR @rts12</pre> | JSR @rts12</pre> | ||
|Clobbers Z, N and A and requires @rts12 | |||
|- | |||
<pre>PHA | |<pre>PHA | ||
TSX | TSX | ||
PLA | PLA | ||
TXS | TXS | ||
PLA</pre> | PLA</pre> | ||
|Clobbers Z, N and X | |||
|- | |||
<pre>PHP | |<pre>PHP | ||
TSX | TSX | ||
PLA | PLA | ||
TXS | TXS | ||
PLP</pre> | PLP</pre> | ||
|Clobbers A and X | |||
|- | |||
<pre>BIT $00 | |<pre>BIT $00 | ||
JSR @rts12</pre> | JSR @rts12</pre> | ||
|Clobbers Z, N and V and requires @rts12 | |||
|- | |||
<pre>STA @zptemp | |<pre>STA @zptemp | ||
JSR @rts12</pre> | JSR @rts12</pre> | ||
|Requires @zptemp and @rts12 | |||
|- | |||
<pre>NOP $00 | |<pre>NOP | ||
PHA | |||
PHA | |||
PHP | |||
PLP</pre> | |||
|Clobbers S | |||
|- | |||
|<pre>NOP $00 | |||
JSR @rts12</pre> | JSR @rts12</pre> | ||
|Requires support for unofficial opcodes and @rts12 | |||
== | |- | ||
|<pre>LDY #130 | |||
@Y = * - 1 | |||
; ^ Hides !NOP #imm | |||
NOP | |||
DEY | |||
BMI @Y</pre> | |||
|Clobbers Z, N and Y and requires support for unofficial opcodes | |||
|- | |||
!colspan="2"|6 bytes | |||
|- | |||
|<pre>NOP | |||
NOP | |||
NOP | |||
NOP | |||
PHP | |||
PLP</pre> | |||
|Clobbers nothing, requires nothing | |||
|- | |||
|} | |||
=== 16 cycles === | === 16 cycles === | ||
== | {| class="wikitable" | ||
!colspan="2"|4 bytes | |||
<pre>PLA | |- | ||
|<pre>NOP | |||
JSR @rts14</pre> | |||
|Requires @rts14 | |||
|- | |||
|<pre>PLA | |||
PLA | PLA | ||
PLA | PLA | ||
PLA</pre> | PLA</pre> | ||
|Clobbers Z, N, A and S | |||
= | |- | ||
!colspan="2"|5 bytes | |||
|- | |||
|<pre>NOP | |||
PHP | |||
PLP | |||
PHP | |||
PLP</pre> | |||
|Clobbers nothing, requires nothing | |||
|- | |||
|} | |||
=== 17 cycles === | === 17 cycles === | ||
== | {| class="wikitable" | ||
!colspan="2"|4 bytes | |||
<pre>NOP | |- | ||
|<pre>NOP | |||
JSR @rts15</pre> | JSR @rts15</pre> | ||
|Requires @rts15 | |||
|- | |||
<pre>PHA | |<pre>PHA | ||
JSR @rts14</pre> | JSR @rts14</pre> | ||
|Clobbers S and requires @rts14 | |||
= | |- | ||
!colspan="2"|5 bytes | |||
<pre>LDA $00 | |- | ||
|<pre>LDA $00 | |||
JSR @rts14</pre> | JSR @rts14</pre> | ||
|Clobbers Z, N and A and requires @rts14 | |||
|- | |||
<pre>BIT $00 | |<pre>BIT $00 | ||
JSR @rts14</pre> | JSR @rts14</pre> | ||
|Clobbers Z, N and V and requires @rts14 | |||
|- | |||
<pre>STA @zptemp | |<pre>STA @zptemp | ||
JSR @rts14</pre> | JSR @rts14</pre> | ||
|Requires @zptemp and @rts14 | |||
|- | |||
<pre>PHA | |<pre>PHA | ||
PHP | PHP | ||
PLP | PLP | ||
PHP | PHP | ||
PLP</pre> | PLP</pre> | ||
|Clobbers S | |||
|- | |||
<pre>NOP $00 | |<pre>NOP $00 | ||
JSR @rts14</pre> | JSR @rts14</pre> | ||
|Requires support for unofficial opcodes and @rts14 | |||
= | |- | ||
!colspan="2"|6 bytes | |||
|- | |||
|<pre>PHP | |||
PLP | |||
PHP | |||
BIT $00 | |||
PLP</pre> | |||
|Clobbers nothing, requires nothing | |||
|- | |||
|} | |||
=== 18 cycles === | === 18 cycles === | ||
== | {| class="wikitable" | ||
!colspan="2"|4 bytes | |||
<pre>PHA | |- | ||
|<pre>PHA | |||
JSR @rts15</pre> | JSR @rts15</pre> | ||
|Clobbers S and requires @rts15 | |||
|- | |||
<pre>PLA | |<pre>PLA | ||
JSR @rts14</pre> | JSR @rts14</pre> | ||
|Clobbers Z, N, A and S and requires @rts14 | |||
|- | |||
!colspan="2"|5 bytes | |||
<pre>LDA $00 | |- | ||
|<pre>LDA $00 | |||
JSR @rts15</pre> | JSR @rts15</pre> | ||
|Clobbers Z, N and A and requires @rts15 | |||
|- | |||
<pre>BIT $00 | |<pre>BIT $00 | ||
JSR @rts15</pre> | JSR @rts15</pre> | ||
|Clobbers Z, N and V and requires @rts15 | |||
|- | |||
<pre>STA @zptemp | |<pre>NOP | ||
NOP | |||
JSR @rts14</pre> | |||
|Requires @rts14 | |||
|- | |||
|<pre>STA @zptemp | |||
JSR @rts15</pre> | JSR @rts15</pre> | ||
|Requires @zptemp and @rts15 | |||
|- | |||
<pre>PHA | |<pre>PHA | ||
PHA | PHA | ||
JSR @rts12</pre> | JSR @rts12</pre> | ||
|Clobbers S and requires @rts12 | |||
|- | |||
<pre>NOP $00 | |<pre>NOP | ||
PLA | |||
PLA | |||
PLA | |||
PLA</pre> | |||
|Clobbers Z, N, A and S | |||
|- | |||
|<pre>NOP $00 | |||
JSR @rts15</pre> | JSR @rts15</pre> | ||
|Requires support for unofficial opcodes and @rts15 | |||
=== | |- | ||
|<pre>LDY #130 | |||
@Y = * - 1 | |||
; ^ Hides !NOP #imm | |||
NOP $EA ;hides 'NOP' | |||
DEY | |||
BMI @Y</pre> | |||
|Clobbers Z, N and Y and requires support for unofficial opcodes | |||
|- | |||
|<pre>LDX #130 | |||
@X = * - 1 | |||
; ^ Hides !NOP #imm | |||
NOP $EA ;hides 'NOP' | |||
DEX | |||
BMI @X</pre> | |||
|Clobbers Z, N and X and requires support for unofficial opcodes | |||
|- | |||
!colspan="2"|6 bytes | |||
|- | |||
|<pre>NOP | |||
NOP | |||
PHP | |||
PLP | |||
PHP | |||
PLP</pre> | |||
|Clobbers nothing, requires nothing | |||
|- | |||
|} | |||
=== 19 cycles === | === 19 cycles === | ||
== | {| class="wikitable" | ||
!colspan="2"|4 bytes | |||
<pre>PLA | |- | ||
|<pre>PLA | |||
JSR @rts15</pre> | JSR @rts15</pre> | ||
|Clobbers Z, N, A and S and requires @rts15 | |||
= | |- | ||
!colspan="2"|5 bytes | |||
<pre>PHP | |- | ||
|<pre>PHP | |||
PLP | PLP | ||
JSR @rts12</pre> | JSR @rts12</pre> | ||
|Requires @rts12 | |||
|- | |||
<pre>NOP | |<pre>NOP | ||
NOP | NOP | ||
JSR @rts15</pre> | JSR @rts15</pre> | ||
|Requires @rts15 | |||
|- | |||
<pre>PHA | |<pre>PHA | ||
PLA | PLA | ||
PLA | PLA | ||
PLA | PLA | ||
PLA</pre> | PLA</pre> | ||
|Clobbers Z, N, A and S | |||
|- | |||
<pre>NOP | |<pre>NOP | ||
PHA | PHA | ||
JSR @rts14</pre> | JSR @rts14</pre> | ||
|Clobbers S and requires @rts14 | |||
= | |- | ||
''Clobbers | |<pre>LDY #130 | ||
<pre>PHP | @Y = * - 1 | ||
; ^ Hides !NOP #imm | |||
NOP $EA,X ;hides 'NOP' | |||
DEY | |||
BMI @Y</pre> | |||
|Clobbers Z, N and Y and requires support for unofficial opcodes | |||
|- | |||
|<pre>LDX #130 | |||
@X = * - 1 | |||
; ^ Hides !NOP #imm | |||
NOP $EA,X ;hides 'NOP' | |||
DEX | |||
BMI @X</pre> | |||
|Clobbers Z, N and X and requires support for unofficial opcodes | |||
|- | |||
!colspan="2"|6 bytes | |||
|- | |||
|<pre>PHP | |||
ROL $00,X | ROL $00,X | ||
ROR $00,X | ROR $00,X | ||
PLP</pre> | PLP</pre> | ||
|Clobbers nothing, requires nothing | |||
|- | |||
|} | |||
=== 20 cycles === | === 20 cycles === | ||
== | {| class="wikitable" | ||
!colspan="2"|5 bytes | |||
<pre>PLA | |- | ||
|<pre>NOP | |||
PHA | |||
JSR @rts15</pre> | |||
|Clobbers S and requires @rts15 | |||
|- | |||
|<pre>PLA | |||
PLA | PLA | ||
PLA | PLA | ||
PLA | PLA | ||
PLA</pre> | PLA</pre> | ||
|Clobbers Z, N, A and S | |||
|- | |||
<pre>PHA | |<pre>PHA | ||
PHA | PHA | ||
JSR @rts14</pre> | JSR @rts14</pre> | ||
|Clobbers S and requires @rts14 | |||
= | |- | ||
'' | |<pre>LDY #130 | ||
<pre>TSX | @Y = * - 1 | ||
; ^ Hides !NOP #imm | |||
NOP $EA44 ;hides 'NOP zp' | |||
DEY | |||
BMI @Y</pre> | |||
|Clobbers Z, N and Y and requires support for unofficial opcodes | |||
|- | |||
|<pre>LDX #130 | |||
@X = * - 1 | |||
; ^ Hides !NOP #imm | |||
NOP $EA44 ;hides 'NOP zp' | |||
DEX | |||
BMI @X</pre> | |||
|Clobbers Z, N and X and requires support for unofficial opcodes | |||
|- | |||
!colspan="2"|6 bytes | |||
|- | |||
|<pre>NOP | |||
LDA $00 | |||
JSR @rts15</pre> | |||
|Clobbers Z, N and A and requires @rts15 | |||
|- | |||
|<pre>TSX | |||
PLA | PLA | ||
PLA | PLA | ||
Line 359: | Line 628: | ||
PLA | PLA | ||
TXS</pre> | TXS</pre> | ||
|Clobbers Z, N, A and X | |||
|- | |||
<pre>PHA | |<pre>NOP | ||
BIT $00 | |||
JSR @rts15</pre> | |||
|Clobbers Z, N and V and requires @rts15 | |||
|- | |||
|<pre>NOP | |||
NOP | |||
NOP | |||
JSR @rts14</pre> | |||
|Requires @rts14 | |||
|- | |||
|<pre>NOP | |||
STA @zptemp | |||
JSR @rts15</pre> | |||
|Requires @zptemp and @rts15 | |||
|- | |||
|<pre>PHA | |||
PHA | PHA | ||
PHP | PHP | ||
Line 367: | Line 652: | ||
PHP | PHP | ||
PLP</pre> | PLP</pre> | ||
|Clobbers S | |||
= | |- | ||
|<pre>NOP | |||
NOP $00 | |||
JSR @rts15</pre> | |||
|Requires support for unofficial opcodes and @rts15 | |||
|- | |||
!colspan="2"|7 bytes | |||
|- | |||
|<pre>NOP | |||
NOP | |||
NOP | |||
PHP | |||
PLP | |||
PHP | |||
PLP</pre> | |||
|Clobbers nothing, requires nothing | |||
|- | |||
|} | |||
=== 21 cycles === | === 21 cycles === | ||
== | {| class="wikitable" | ||
!colspan="2"|5 bytes | |||
<pre>LDY #4 | |- | ||
@ | |<pre>LDY #4 | ||
@Y: | |||
DEY | DEY | ||
BNE @ | BNE @Y</pre> | ||
|Clobbers Z, N and Y | |||
|- | |||
<pre>LDX #4 | |<pre>LDX #4 | ||
@ | @X: | ||
DEX | DEX | ||
BNE @ | BNE @X</pre> | ||
|Clobbers Z, N and X | |||
|- | |||
<pre>PHA | |<pre>PHP | ||
PLP | |||
JSR @rts14</pre> | |||
|Requires @rts14 | |||
|- | |||
|<pre>PHA | |||
PHA | PHA | ||
JSR @rts15</pre> | JSR @rts15</pre> | ||
|Clobbers S and requires @rts15 | |||
= | |- | ||
!colspan="2"|6 bytes | |||
|- | |||
|<pre>PHP | |||
PLP | |||
PHP | |||
PLP | |||
PHP | |||
PLP</pre> | |||
|Clobbers nothing, requires nothing | |||
|- | |||
|} | |||
=== 22 cycles === | === 22 cycles === | ||
== | {| class="wikitable" | ||
!colspan="2"|5 bytes | |||
<pre>PHP | |- | ||
|<pre>PHP | |||
PLP | PLP | ||
JSR @rts15</pre> | JSR @rts15</pre> | ||
|Requires @rts15 | |||
|- | |||
<pre>PLA | |<pre>PLA | ||
PLA | PLA | ||
JSR @rts14</pre> | JSR @rts14</pre> | ||
|Clobbers Z, N, A and S and requires @rts14 | |||
= | |- | ||
'' | |<pre>LDY #130 | ||
<pre>LDY #3 | @Y = * - 1 | ||
@ | ; ^ Hides !NOP #imm | ||
.byte $0C,$E6,@zp_temp ;NOP abs; hides 'INC @zp_temp' | |||
DEY | |||
BMI @Y</pre> | |||
|Clobbers Z, N and Y and requires support for unofficial opcodes and @zptemp | |||
|- | |||
|<pre>LDX #130 | |||
@X = * - 1 | |||
; ^ Hides !NOP #imm | |||
.byte $0C,$E6,@zp_temp ;NOP abs; hides 'INC @zp_temp' | |||
DEX | |||
BMI @X</pre> | |||
|Clobbers Z, N and X and requires support for unofficial opcodes and @zptemp | |||
|- | |||
!colspan="2"|6 bytes | |||
|- | |||
|<pre>LDY #3 | |||
@Y: | |||
NOP | NOP | ||
DEY | DEY | ||
BNE @ | BNE @Y</pre> | ||
|Clobbers Z, N and Y | |||
|- | |||
<pre>LDX #3 | |<pre>LDX #3 | ||
@ | @X: | ||
NOP | NOP | ||
DEX | DEX | ||
BNE @ | BNE @X</pre> | ||
|Clobbers Z, N and X | |||
|- | |||
<pre>PHA | |<pre>PHA | ||
PHP | PHP | ||
PLP | PLP | ||
JSR @rts12</pre> | JSR @rts12</pre> | ||
|Clobbers S and requires @rts12 | |||
= | |- | ||
|<pre>NOP | |||
<pre>PHP | PLA | ||
PLA | |||
PLA | |||
PLA | |||
PLA</pre> | |||
|Clobbers Z, N, A and S | |||
|- | |||
|<pre>NOP | |||
PHA | |||
PHA | |||
JSR @rts14</pre> | |||
|Clobbers S and requires @rts14 | |||
|- | |||
!colspan="2"|7 bytes | |||
|- | |||
|<pre>PHP | |||
BIT $00 | BIT $00 | ||
PLP | PLP | ||
JSR @rts12</pre> | JSR @rts12</pre> | ||
|Requires @rts12 | |||
|- | |||
<pre>PHP | |<pre>PHP | ||
PHA | PHA | ||
TSX | TSX | ||
Line 443: | Line 793: | ||
PLA | PLA | ||
PLP</pre> | PLP</pre> | ||
|Clobbers X | |||
=== | |- | ||
|<pre>NOP | |||
NOP | |||
NOP | |||
NOP | |||
JSR @rts14</pre> | |||
|Requires @rts14 | |||
|- | |||
|<pre>NOP | |||
PHA | |||
PHA | |||
PHP | |||
PLP | |||
PHP | |||
PLP</pre> | |||
|Clobbers S | |||
|- | |||
|<pre>PHP | |||
LDY #130 | |||
@Y = * - 1 | |||
; ^ Hides !NOP #imm | |||
NOP | |||
DEY | |||
BMI @Y | |||
PLP</pre> | |||
|Clobbers Y and requires support for unofficial opcodes | |||
|- | |||
|<pre>SEC | |||
LDA #130 | |||
@A = * - 1 | |||
; ^ Hides !NOP #imm | |||
NOP $EA44 ;hides 'NOP zp' | |||
SBC #1 | |||
BMI @A</pre> | |||
|Clobbers C, Z, N and A and requires support for unofficial opcodes | |||
|- | |||
!colspan="2"|8 bytes | |||
|- | |||
|<pre>NOP | |||
NOP | |||
NOP | |||
NOP | |||
PHP | |||
PLP | |||
PHP | |||
PLP</pre> | |||
|Clobbers nothing, requires nothing | |||
|- | |||
|} | |||
=== 23 cycles === | === 23 cycles === | ||
== | {| class="wikitable" | ||
!colspan="2"|5 bytes | |||
<pre>PLA | |- | ||
|<pre>PLA | |||
PLA | PLA | ||
JSR @rts15</pre> | JSR @rts15</pre> | ||
|Clobbers Z, N, A and S and requires @rts15 | |||
= | |- | ||
'' | |<pre>LDX #130 | ||
<pre>TSX | @X = * - 1 | ||
; ^ Hides !NOP #imm | |||
NOP $4848 ;hides two 'PHA's | |||
DEX | |||
BMI @X</pre> | |||
|Clobbers Z, N, X and S and requires support for unofficial opcodes | |||
|- | |||
|<pre>LDY #130 | |||
@Y = * - 1 | |||
; ^ Hides !NOP #imm | |||
NOP $4848 ;hides two 'PHA's | |||
DEY | |||
BMI @Y</pre> | |||
|Clobbers Z, N, Y and S and requires support for unofficial opcodes | |||
|- | |||
!colspan="2"|6 bytes | |||
|- | |||
|<pre>TSX | |||
PLA | PLA | ||
TXS | TXS | ||
JSR @rts15</pre> | JSR @rts15</pre> | ||
|Clobbers Z, N, A and X and requires @rts15 | |||
|- | |||
<pre>PHA | |<pre>NOP | ||
PHP | |||
PLP | |||
JSR @rts14</pre> | |||
|Requires @rts14 | |||
|- | |||
|<pre>NOP | |||
PHA | |||
PHA | |||
JSR @rts15</pre> | |||
|Clobbers S and requires @rts15 | |||
|- | |||
|<pre>PHA | |||
PLA | PLA | ||
PLA | PLA | ||
Line 469: | Line 896: | ||
PLA | PLA | ||
PLA</pre> | PLA</pre> | ||
|Clobbers Z, N, A and S | |||
=== | |- | ||
|<pre>LDY #130 | |||
@Y = * - 1 | |||
; ^ Hides !NOP #imm | |||
NOP $EA,X ;hides 'NOP' | |||
NOP | |||
DEY | |||
BMI @Y</pre> | |||
|Clobbers Z, N and Y and requires support for unofficial opcodes | |||
|- | |||
|<pre>LDX #130 | |||
@X = * - 1 | |||
; ^ Hides !NOP #imm | |||
NOP $EA,X ;hides 'NOP' | |||
NOP | |||
DEX | |||
BMI @X</pre> | |||
|Clobbers Z, N and X and requires support for unofficial opcodes | |||
|- | |||
!colspan="2"|7 bytes | |||
|- | |||
|<pre>NOP | |||
PHP | |||
PLP | |||
PHP | |||
PLP | |||
PHP | |||
PLP</pre> | |||
|Clobbers nothing, requires nothing | |||
|- | |||
|} | |||
=== 24 cycles === | === 24 cycles === | ||
== | {| class="wikitable" | ||
'' | !colspan="2"|5 bytes | ||
<pre>JSR @rts12 | |- | ||
|<pre>LDY #130 | |||
@Y = * - 1 | |||
; ^ Hides !NOP #imm | |||
NOP $2808 ;hides 'PHP' and 'PLP'; reads from $2000 | |||
DEY | |||
BMI @Y</pre> | |||
|Clobbers Z, N and Y and requires support for unofficial opcodes | |||
|- | |||
|<pre>LDX #130 | |||
@X = * - 1 | |||
; ^ Hides !NOP #imm | |||
NOP $2808 ;hides 'PHP' and 'PLP'; reads from $2000 | |||
DEX | |||
BMI @X</pre> | |||
|Clobbers Z, N and X and requires support for unofficial opcodes | |||
|- | |||
!colspan="2"|6 bytes | |||
|- | |||
|<pre>JSR @rts12 | |||
JSR @rts12</pre> | JSR @rts12</pre> | ||
|Requires @rts12 | |||
|- | |||
<pre>NOP | |<pre>NOP | ||
PHP | PHP | ||
PLP | PLP | ||
JSR @rts15</pre> | JSR @rts15</pre> | ||
|Requires @rts15 | |||
|- | |||
<pre>PLA | |<pre>PLA | ||
PLA | PLA | ||
PLA | PLA | ||
Line 493: | Line 968: | ||
PLA | PLA | ||
PLA</pre> | PLA</pre> | ||
|Clobbers Z, N, A and S | |||
|- | |||
<pre>PHA | |<pre>PHA | ||
PHP | PHP | ||
PLP | PLP | ||
JSR @rts14</pre> | JSR @rts14</pre> | ||
|Clobbers S and requires @rts14 | |||
= | |- | ||
!colspan="2"|7 bytes | |||
<pre>TSX | |- | ||
|<pre>TSX | |||
PLA | PLA | ||
PLA | PLA | ||
Line 509: | Line 985: | ||
PLA | PLA | ||
TXS</pre> | TXS</pre> | ||
|Clobbers Z, N, A and X | |||
|- | |||
<pre>PHP | |<pre>PHP | ||
BIT $00 | BIT $00 | ||
PLP | PLP | ||
JSR @rts14</pre> | JSR @rts14</pre> | ||
|Requires @rts14 | |||
|- | |||
<pre>PHA | |<pre>PHA | ||
PHP | |||
PLP | |||
PHP | |||
PLP | |||
PHP | PHP | ||
PLP</pre> | |||
|Clobbers S | |||
|- | |||
|<pre>SEC | |||
LDA #130 | |||
@A = * - 1 | |||
; ^ Hides !NOP #imm | |||
.byte $0C,$E6,@zp_temp ;NOP abs; hides 'INC @zp_temp' | |||
SBC #1 | |||
BMI @A</pre> | |||
|Clobbers C, Z, N and A and requires support for unofficial opcodes and @zptemp | |||
|- | |||
!colspan="2"|8 bytes | |||
|- | |||
|<pre>PHP | |||
PLP | PLP | ||
PHP | PHP | ||
PLP | PLP | ||
PHP | PHP | ||
BIT $00 | |||
PLP</pre> | PLP</pre> | ||
|Clobbers nothing, requires nothing | |||
|- | |||
|} | |||
== More == | == More == | ||
Bisqwit's 6502 delay_n macro set for ca65: http://bisqwit.iki.fi/src/6502-inline_delay.7z | Bisqwit's 6502 delay_n macro set for ca65: http://bisqwit.iki.fi/src/6502-inline_delay.7z |
Revision as of 00:22, 14 March 2016
Delay code
Shortest possible CPU code that creates N cycles of delay, depending on constraints.
All branch instructions assume that no page wrap occurs.
Explanations on the requirements:
- @zp_temp means you have a zeropage address that you can write random data into.
- @rts12 means you know a memory address that contains byte $60 (
RTS
). - @rts14 means you know a memory address that contains a harmless 2-cycle instruction that fits your constraints (such as
CLC
,LDA #0
, orNOP
), followed byRTS
. - @rts15 means you know a memory address that contains a
JMP
that jumps to another location that containsRTS
. - Alternatively, @rts15 means you know a memory address that contains a harmless 3-cycle instruction that fits your constraints (such as
LDA $00
), followed byRTS
. - @A, @X, @Y are local labels.
2 cycles
1 bytes | |
---|---|
NOP |
Clobbers nothing, requires nothing |
3 cycles
1 bytes | |
---|---|
PHA |
Clobbers S |
2 bytes | |
LDA $00 |
Clobbers Z, N and A |
BIT $00 |
Clobbers Z, N and V |
STA @zptemp |
Requires @zptemp |
NOP $00 |
Requires support for unofficial opcodes |
3 bytes | |
JMP *+3 |
Clobbers nothing, requires nothing |
4 cycles
1 bytes | |
---|---|
PLA |
Clobbers Z, N, A and S |
2 bytes | |
NOP NOP |
Clobbers nothing, requires nothing |
5 cycles
2 bytes | |
---|---|
NOP PHA |
Clobbers S |
3 bytes | |
NOP LDA $00 |
Clobbers Z, N and A |
NOP BIT $00 |
Clobbers Z, N and V |
NOP STA @zptemp |
Requires @zptemp |
NOP NOP $00 |
Requires support for unofficial opcodes |
4 bytes | |
NOP JMP *+3 |
Clobbers nothing, requires nothing |
6 cycles
2 bytes | |
---|---|
PHA PHA |
Clobbers S |
3 bytes | |
NOP NOP NOP |
Clobbers nothing, requires nothing |
7 cycles
2 bytes | |
---|---|
PHP PLP |
Clobbers nothing, requires nothing |
8 cycles
2 bytes | |
---|---|
PLA PLA |
Clobbers Z, N, A and S |
3 bytes | |
TSX PLA TXS |
Clobbers Z, N, A and X |
NOP PHA PHA |
Clobbers S |
4 bytes | |
NOP NOP NOP NOP |
Clobbers nothing, requires nothing |
9 cycles
3 bytes | |
---|---|
NOP PHP PLP |
Clobbers nothing, requires nothing |
10 cycles
3 bytes | |
---|---|
PHA PHP PLP |
Clobbers S |
4 bytes | |
PHP BIT $00 PLP |
Clobbers nothing, requires nothing |
11 cycles
3 bytes | |
---|---|
PHA PLA PLA |
Clobbers Z, N, A and S |
4 bytes | |
NOP NOP PHP PLP |
Clobbers nothing, requires nothing |
12 cycles
3 bytes | |
---|---|
JSR @rts12 |
Requires @rts12 |
PLA PLA PLA |
Clobbers Z, N, A and S |
4 bytes | |
ROL $00,X ROR $00,X |
Clobbers Z and N |
NOP PHA PHP PLP |
Clobbers S |
5 bytes | |
NOP PHP BIT $00 PLP |
Clobbers nothing, requires nothing |
13 cycles
4 bytes | |
---|---|
PHA PHA PHP PLP |
Clobbers S |
5 bytes | |
NOP NOP NOP PHP PLP |
Clobbers nothing, requires nothing |
14 cycles
3 bytes | |
---|---|
JSR @rts14 |
Requires @rts14 |
4 bytes | |
PHP PLP PHP PLP |
Clobbers nothing, requires nothing |
15 cycles
3 bytes | |
---|---|
JSR @rts15 |
Requires @rts15 |
4 bytes | |
PHA JSR @rts12 |
Clobbers S and requires @rts12 |
PHA PLA PLA PLA |
Clobbers Z, N, A and S |
5 bytes | |
LDA $00 JSR @rts12 |
Clobbers Z, N and A and requires @rts12 |
PHA TSX PLA TXS PLA |
Clobbers Z, N and X |
PHP TSX PLA TXS PLP |
Clobbers A and X |
BIT $00 JSR @rts12 |
Clobbers Z, N and V and requires @rts12 |
STA @zptemp JSR @rts12 |
Requires @zptemp and @rts12 |
NOP PHA PHA PHP PLP |
Clobbers S |
NOP $00 JSR @rts12 |
Requires support for unofficial opcodes and @rts12 |
LDY #130 @Y = * - 1 ; ^ Hides !NOP #imm NOP DEY BMI @Y |
Clobbers Z, N and Y and requires support for unofficial opcodes |
6 bytes | |
NOP NOP NOP NOP PHP PLP |
Clobbers nothing, requires nothing |
16 cycles
4 bytes | |
---|---|
NOP JSR @rts14 |
Requires @rts14 |
PLA PLA PLA PLA |
Clobbers Z, N, A and S |
5 bytes | |
NOP PHP PLP PHP PLP |
Clobbers nothing, requires nothing |
17 cycles
4 bytes | |
---|---|
NOP JSR @rts15 |
Requires @rts15 |
PHA JSR @rts14 |
Clobbers S and requires @rts14 |
5 bytes | |
LDA $00 JSR @rts14 |
Clobbers Z, N and A and requires @rts14 |
BIT $00 JSR @rts14 |
Clobbers Z, N and V and requires @rts14 |
STA @zptemp JSR @rts14 |
Requires @zptemp and @rts14 |
PHA PHP PLP PHP PLP |
Clobbers S |
NOP $00 JSR @rts14 |
Requires support for unofficial opcodes and @rts14 |
6 bytes | |
PHP PLP PHP BIT $00 PLP |
Clobbers nothing, requires nothing |
18 cycles
4 bytes | |
---|---|
PHA JSR @rts15 |
Clobbers S and requires @rts15 |
PLA JSR @rts14 |
Clobbers Z, N, A and S and requires @rts14 |
5 bytes | |
LDA $00 JSR @rts15 |
Clobbers Z, N and A and requires @rts15 |
BIT $00 JSR @rts15 |
Clobbers Z, N and V and requires @rts15 |
NOP NOP JSR @rts14 |
Requires @rts14 |
STA @zptemp JSR @rts15 |
Requires @zptemp and @rts15 |
PHA PHA JSR @rts12 |
Clobbers S and requires @rts12 |
NOP PLA PLA PLA PLA |
Clobbers Z, N, A and S |
NOP $00 JSR @rts15 |
Requires support for unofficial opcodes and @rts15 |
LDY #130 @Y = * - 1 ; ^ Hides !NOP #imm NOP $EA ;hides 'NOP' DEY BMI @Y |
Clobbers Z, N and Y and requires support for unofficial opcodes |
LDX #130 @X = * - 1 ; ^ Hides !NOP #imm NOP $EA ;hides 'NOP' DEX BMI @X |
Clobbers Z, N and X and requires support for unofficial opcodes |
6 bytes | |
NOP NOP PHP PLP PHP PLP |
Clobbers nothing, requires nothing |
19 cycles
4 bytes | |
---|---|
PLA JSR @rts15 |
Clobbers Z, N, A and S and requires @rts15 |
5 bytes | |
PHP PLP JSR @rts12 |
Requires @rts12 |
NOP NOP JSR @rts15 |
Requires @rts15 |
PHA PLA PLA PLA PLA |
Clobbers Z, N, A and S |
NOP PHA JSR @rts14 |
Clobbers S and requires @rts14 |
LDY #130 @Y = * - 1 ; ^ Hides !NOP #imm NOP $EA,X ;hides 'NOP' DEY BMI @Y |
Clobbers Z, N and Y and requires support for unofficial opcodes |
LDX #130 @X = * - 1 ; ^ Hides !NOP #imm NOP $EA,X ;hides 'NOP' DEX BMI @X |
Clobbers Z, N and X and requires support for unofficial opcodes |
6 bytes | |
PHP ROL $00,X ROR $00,X PLP |
Clobbers nothing, requires nothing |
20 cycles
5 bytes | |
---|---|
NOP PHA JSR @rts15 |
Clobbers S and requires @rts15 |
PLA PLA PLA PLA PLA |
Clobbers Z, N, A and S |
PHA PHA JSR @rts14 |
Clobbers S and requires @rts14 |
LDY #130 @Y = * - 1 ; ^ Hides !NOP #imm NOP $EA44 ;hides 'NOP zp' DEY BMI @Y |
Clobbers Z, N and Y and requires support for unofficial opcodes |
LDX #130 @X = * - 1 ; ^ Hides !NOP #imm NOP $EA44 ;hides 'NOP zp' DEX BMI @X |
Clobbers Z, N and X and requires support for unofficial opcodes |
6 bytes | |
NOP LDA $00 JSR @rts15 |
Clobbers Z, N and A and requires @rts15 |
TSX PLA PLA PLA PLA TXS |
Clobbers Z, N, A and X |
NOP BIT $00 JSR @rts15 |
Clobbers Z, N and V and requires @rts15 |
NOP NOP NOP JSR @rts14 |
Requires @rts14 |
NOP STA @zptemp JSR @rts15 |
Requires @zptemp and @rts15 |
PHA PHA PHP PLP PHP PLP |
Clobbers S |
NOP NOP $00 JSR @rts15 |
Requires support for unofficial opcodes and @rts15 |
7 bytes | |
NOP NOP NOP PHP PLP PHP PLP |
Clobbers nothing, requires nothing |
21 cycles
5 bytes | |
---|---|
LDY #4 @Y: DEY BNE @Y |
Clobbers Z, N and Y |
LDX #4 @X: DEX BNE @X |
Clobbers Z, N and X |
PHP PLP JSR @rts14 |
Requires @rts14 |
PHA PHA JSR @rts15 |
Clobbers S and requires @rts15 |
6 bytes | |
PHP PLP PHP PLP PHP PLP |
Clobbers nothing, requires nothing |
22 cycles
5 bytes | |
---|---|
PHP PLP JSR @rts15 |
Requires @rts15 |
PLA PLA JSR @rts14 |
Clobbers Z, N, A and S and requires @rts14 |
LDY #130 @Y = * - 1 ; ^ Hides !NOP #imm .byte $0C,$E6,@zp_temp ;NOP abs; hides 'INC @zp_temp' DEY BMI @Y |
Clobbers Z, N and Y and requires support for unofficial opcodes and @zptemp |
LDX #130 @X = * - 1 ; ^ Hides !NOP #imm .byte $0C,$E6,@zp_temp ;NOP abs; hides 'INC @zp_temp' DEX BMI @X |
Clobbers Z, N and X and requires support for unofficial opcodes and @zptemp |
6 bytes | |
LDY #3 @Y: NOP DEY BNE @Y |
Clobbers Z, N and Y |
LDX #3 @X: NOP DEX BNE @X |
Clobbers Z, N and X |
PHA PHP PLP JSR @rts12 |
Clobbers S and requires @rts12 |
NOP PLA PLA PLA PLA PLA |
Clobbers Z, N, A and S |
NOP PHA PHA JSR @rts14 |
Clobbers S and requires @rts14 |
7 bytes | |
PHP BIT $00 PLP JSR @rts12 |
Requires @rts12 |
PHP PHA TSX PLA TXS PLA PLP |
Clobbers X |
NOP NOP NOP NOP JSR @rts14 |
Requires @rts14 |
NOP PHA PHA PHP PLP PHP PLP |
Clobbers S |
PHP LDY #130 @Y = * - 1 ; ^ Hides !NOP #imm NOP DEY BMI @Y PLP |
Clobbers Y and requires support for unofficial opcodes |
SEC LDA #130 @A = * - 1 ; ^ Hides !NOP #imm NOP $EA44 ;hides 'NOP zp' SBC #1 BMI @A |
Clobbers C, Z, N and A and requires support for unofficial opcodes |
8 bytes | |
NOP NOP NOP NOP PHP PLP PHP PLP |
Clobbers nothing, requires nothing |
23 cycles
5 bytes | |
---|---|
PLA PLA JSR @rts15 |
Clobbers Z, N, A and S and requires @rts15 |
LDX #130 @X = * - 1 ; ^ Hides !NOP #imm NOP $4848 ;hides two 'PHA's DEX BMI @X |
Clobbers Z, N, X and S and requires support for unofficial opcodes |
LDY #130 @Y = * - 1 ; ^ Hides !NOP #imm NOP $4848 ;hides two 'PHA's DEY BMI @Y |
Clobbers Z, N, Y and S and requires support for unofficial opcodes |
6 bytes | |
TSX PLA TXS JSR @rts15 |
Clobbers Z, N, A and X and requires @rts15 |
NOP PHP PLP JSR @rts14 |
Requires @rts14 |
NOP PHA PHA JSR @rts15 |
Clobbers S and requires @rts15 |
PHA PLA PLA PLA PLA PLA |
Clobbers Z, N, A and S |
LDY #130 @Y = * - 1 ; ^ Hides !NOP #imm NOP $EA,X ;hides 'NOP' NOP DEY BMI @Y |
Clobbers Z, N and Y and requires support for unofficial opcodes |
LDX #130 @X = * - 1 ; ^ Hides !NOP #imm NOP $EA,X ;hides 'NOP' NOP DEX BMI @X |
Clobbers Z, N and X and requires support for unofficial opcodes |
7 bytes | |
NOP PHP PLP PHP PLP PHP PLP |
Clobbers nothing, requires nothing |
24 cycles
5 bytes | |
---|---|
LDY #130 @Y = * - 1 ; ^ Hides !NOP #imm NOP $2808 ;hides 'PHP' and 'PLP'; reads from $2000 DEY BMI @Y |
Clobbers Z, N and Y and requires support for unofficial opcodes |
LDX #130 @X = * - 1 ; ^ Hides !NOP #imm NOP $2808 ;hides 'PHP' and 'PLP'; reads from $2000 DEX BMI @X |
Clobbers Z, N and X and requires support for unofficial opcodes |
6 bytes | |
JSR @rts12 JSR @rts12 |
Requires @rts12 |
NOP PHP PLP JSR @rts15 |
Requires @rts15 |
PLA PLA PLA PLA PLA PLA |
Clobbers Z, N, A and S |
PHA PHP PLP JSR @rts14 |
Clobbers S and requires @rts14 |
7 bytes | |
TSX PLA PLA PLA PLA PLA TXS |
Clobbers Z, N, A and X |
PHP BIT $00 PLP JSR @rts14 |
Requires @rts14 |
PHA PHP PLP PHP PLP PHP PLP |
Clobbers S |
SEC LDA #130 @A = * - 1 ; ^ Hides !NOP #imm .byte $0C,$E6,@zp_temp ;NOP abs; hides 'INC @zp_temp' SBC #1 BMI @A |
Clobbers C, Z, N and A and requires support for unofficial opcodes and @zptemp |
8 bytes | |
PHP PLP PHP PLP PHP BIT $00 PLP |
Clobbers nothing, requires nothing |
More
Bisqwit's 6502 delay_n macro set for ca65: http://bisqwit.iki.fi/src/6502-inline_delay.7z