Tjoppen Posted June 27, 2011 Share Posted June 27, 2011 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.. Quote Link to comment Share on other sites More sharing options...
Omegamatrix Posted June 27, 2011 Share Posted June 27, 2011 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. Quote Link to comment Share on other sites More sharing options...
Tjoppen Posted June 27, 2011 Author Share Posted June 27, 2011 You're right, the SLEEP macro does use $04. That's quite reassuring. Indded, using $80 for delay tables is a very neat hack. Quote Link to comment Share on other sites More sharing options...
+batari Posted June 27, 2011 Share Posted June 27, 2011 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. Quote Link to comment Share on other sites More sharing options...
Omegamatrix Posted June 29, 2011 Share Posted June 29, 2011 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). Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted June 29, 2011 Share Posted June 29, 2011 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.