Jump to content
IGNORED

Why not NOP Imm/Abs-trick instead of BIT ZP/Abs-trick?


Tjoppen

Recommended Posts

While browsing through the undocumented 6502 opcodes today I realized one should be able to replace all of one's BIT tricks with NOP tricks.

After going through the tables I found two interesting characters (there appear to be duplicates):

 

$80: NOP #Imm = 2 B, 2 cycles, affects no flags, aka DOP

$0C: NOP Abs = 3 B, 4 cycles, affects no flags, aka TOP

 

compared to the "normal"

 

$24: BIT ZP = 2 B, 3 cycles, affects NVZ

$2C: BIT Abs = 3 B, 4 cycles, affects NVZ

 

NOP #Imm in particular is useful since it allows skipping one byte one cycle faster compared to BIT ZP.

NOP Abs is useful mostly because it doesn't affect the status flags like BIT Abs does, which could be useful in some tightly optimized loop.

 

Has anyone used either of these and found any problems with them? I tried searching around, but didn't come up with much.

Luckily I haven't yet reached a state where I'd need either of these, but they could prove useful..

Link to comment
Share on other sites

Illegal NOP's have never caused any problems that I am aware of. I believe the SLEEP macro even employs them. The beauty like you say is they preserve all flags, where as BIT will affect NVZ. There is also a $04 (NOP zero page) which will delay 3 cycles.

 

 

Besides bankswitching (or just skipping over a few bytes) illegal nops are wonderful to make delay tables out of. Handy when you need to waste time inside a kernel efficiently. The best I've come up with is linked below:

 

 

http://www.atariage.com/forums/topic/180714-request-for-programming-tips/page__view__findpost__p__2264304

 

 

You can expand or contract that table as you wish. It's easy to use. For example if you wanted to delay 22 cycles you would add a JSR WasteTime+14 into your code, and during that delay all your flags will remain the same.

Link to comment
Share on other sites

Illegal NOPs have caused problems. In "normal" bankswitching, these problems would be rare and would only happen if trying to skip somewhat obscure instruction/operand combinations. An example that would cause a bankswitch in F4:

 .byte $0C
 SBC $9F,x

 

However, if programming for Superchip, Supercharger, 3F, 0840, and some others, these problems are not rare at all. It's wise to not use these indiscriminately when using any non-standard bankswitching scheme.

Link to comment
Share on other sites

Yes, these could cause a hotspot to trigger, but the same thing will happen when using BIT or CMP to skip a few bytes. You just have to be aware what address is being formed by the bytes you are jumping over.

 

Like in your example, SBC $9F,x is equal to $9FF5 (or $FFF5 on the 6507).

Link to comment
Share on other sites

Because there's no guarantee that the illegal opcode would be implemented in something, although it didn't happen with illegal NOP's (yet). It wasn't too long ago that the Flashback2 was released, ya know.

 

BTW a 2-cycle byte skip can be done with other 2-cycle instructions (i.e. CMP#, etc). The same can be said of BIT$abs. There's a lot of choices when flags don't matter.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...