Speed patches - reduce game logic time by up to 3,2%

FrankenGraphics

New member
Version 2 - now with partial mini unroll:
Replacing the two files in your engine directory with these saves you 2,4-3,2% game logic time each frame - the more sprites on screen, the more savings to collect, but with the base saving raised compared to v.1.

Just in case, though it should be fine - If version 2 gives you the "value out of range" error, you need to trim down the source size of the same bank that "zeroOutAssets.asm" goes into, by something like 6 bytes.

https://frankengraphics.files.wordpress.com/2020/03/nesmaker-sprite-optimizer2.zip

Version 1:
Replacing the two files in your engine directory with these saves you 1,6-2,4% game logic time each frame - the more sprites on screen, the more savings to collect.

https://frankengraphics.files.wordpress.com/2020/03/nesmaker-sprite-optimizer.zip

What these modified routines do
These are plug and play replacement for 2 vanilla routines in nesmaker that were easy to make better. The operation of and general structure of these routines remain largely unchanged except where it doesn't matter to the programmer, so it should be compatible with whatever other changes you've done. For example, nesmaker does sprite prioritizing by object sorting rather than actual sprite cycling, which is somewhat slow method ideally only for use with slanted topdowners under the best of circumstances (read: custom engine specializing on a genre), but also makes this particular upgrade easy to pass in as a mini module since the object and sprite operations are isolated from each other.

Quick note on how slowdowns work
if game logic takes more than one render-time to compute before it is time to update the PPU during the vBlank period, game logic will carry over to complete during the next frame. This decreases the speed of the game by half momentarily.
Bigger savings doesn't mean the game runs faster, but it raises the roof for how much can be going on before overstepping that threshold. So the bigger the savings, the more stable the flow of the game will be.

quick note on undocumented/illegal opcodes
These new routines are making use of the undocumented/illegal opcode AXS (which carries out x = (A && X ) - #immediate in 2 cycles). There is nothing wrong or dangerous using so-called illegal opcodes so long as they're stable, and AXS is one such. They're called such because their existence is an unintentional bonus fact/happy accident of how they designed the processor to be cheap, which means an opcode outside of definition will combine microcode logic in sometimes interesting ways depending on the bits of the operator. Since they were unintentional, MOS technology didn't include descriptions of them in their official programmers' reference, and that means there are no authoritative, official mnemonics for these instructions - it can vary from assembler to assembler. Hence "illegal". Asm6 doesn't support AXS (or any other undocumented opcode), so i'm instead emitting the opcode for AXS and its operand as raw data, which works just as fine. But it requires a little bit of mental signed hexadecimal arithmetic if you want to change its operand.

Here is a list of all undocumented opcodes that are considered stable. most of them are kind of pointless except extremely circumstantially. just posting them here for reference.
https://cc65.github.io/doc/ca65.html#ss4.3

They work fine on your original nes as well as almost every emulator. Chances are that if some emulator doesn't support it, it is someones' unfinished hobby project that noone is using.
Just telling about it for full disclosure.
 

dale_coop

Moderator
Staff member
Thank you FrankenGraphics for sharing those great scripts. I used it on my current projects, I have no issue with them, only benefits <3
 

Mugi

Member
for those interested, here's our fork for ASM6f assembler that DOES support illegal opcodes.
we extensively use this assembler in dimension shift. At the time of writing the official github builds of asm6f have a bug that prevents some of the illegal opcodes from working, so I'm linking our own fork instead.
This version has been updated to handle all stable illegal opcodes correctly.

https://github.com/FIX94/asm6f

this assembler is an extended version of the standard ASM6 which nesmaker uses, and can be used as a drop-in replacement for nesmaker projects (rename it to asm6.exe and replace the existing one in nesmaker folder.)
 
Top Bottom