lscharen / iigs-game-engine

A tile-based game engine for the Apple IIgs written in 65816 asssembly language
32 stars 1 forks source link

Optimize exit code from blitter #5

Open lscharen opened 2 years ago

lscharen commented 2 years ago

There are two optimization opportunities in the blitter exit paths

  1. The even_exit path just does a double JMP. If the JML can be deferred to a second bank, then the JMP exit_even instructions can be a direct JMP to the next blitter line. Exiting will require patching two JMP instructions instead of 1, but that's only a single extra STA per frame vs savings of 3 cyclers per line
  2. The odd_exit path can be possibly be optimized by doing extra work when saving the PEA field opcode to determine which exit path to take and avoid the two BIT/BEQ tests. There may be a way to only save the operand bytes, too. This optimization will need to look at how SaveOpcode, SaveHighOperand, RestoreOperand and blitter code works together to come up with an overall more efficient solution.
lscharen commented 1 year ago

This optimization is likely infeasible for the general blitter, but the GTE_LITE blitter that holds the entire PEA field in one bank could benefit.

Because adjacent lines of code are close in memory, there are three levels of optimization

  1. For even blits that terminate near the end of a line, the BRA opcode can branch directly to the start of the next line, skipping 2 JMP instructions
  2. For even blits that cannot reach the next line, a sBRA + JMP to jump directly to the next line
  3. For odd blits, set up the code to fall through to the next line, avoiding one JMP.