Jump to content



0

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


5 replies to this topic

#1 Tjoppen ONLINE  

Tjoppen

    Chopper Commander

  • 130 posts

Posted Mon Jun 27, 2011 11:58 AM

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..

#2 Omegamatrix OFFLINE  

Omegamatrix

    River Patroller

  • 4,796 posts
  • Location:Oh, Canada

Posted Mon Jun 27, 2011 12:26 PM

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....ost__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.

#3 Tjoppen ONLINE  

Tjoppen

    Chopper Commander

  • 130 posts

Posted Mon Jun 27, 2011 3:09 PM

You're right, the SLEEP macro does use $04. That's quite reassuring.
Indded, using $80 for delay tables is a very neat hack.

#4 batari OFFLINE  

batari

    )66]U('=I;B$*

  • 6,236 posts
  • begin 644 contest

Posted Mon Jun 27, 2011 3:43 PM

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.

#5 Omegamatrix OFFLINE  

Omegamatrix

    River Patroller

  • 4,796 posts
  • Location:Oh, Canada

Posted Wed Jun 29, 2011 3:34 PM

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).

#6 Nukey Shay ONLINE  

Nukey Shay

    Sheik Yerbouti

  • 20,458 posts
  • Location:The land of Gorch

Posted Wed Jun 29, 2011 5:09 PM

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.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users