User Tools

Site Tools


base:variable_speedcode_runlength

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
base:variable_speedcode_runlength [2016-04-16 12:00]
bitbreaker
base:variable_speedcode_runlength [2022-01-14 12:45] (current)
bitbreaker
Line 26: Line 26:
 </code> </code>
  
-So given the above example, we might want to enter at sta $0400 and leave after sta $0408, to do so we can modify the code and transform the upcoming sta to an rts command. After exiting the speedcode we then modify the rts back to a sta. Pretty nuch overhead and we would even need to call our speedcode as a subroutine. +So given the above example, we might want to enter at sta $0400 and leave after sta $0408, to do so we can modify the code and transform the upcoming sta to an rts command. After exiting the speedcode we then modify the rts back to a sta. Pretty much overhead and we would even need to call our speedcode as a subroutine. We can also leave the speedcode by a timed NMI, but that will also mean overhead in setting up and it will cost extra cycles for the IRQ and RTI
-If we speedocde with predictable runlengths (so no random penalty cycles apply) we could set up a timer irq that will trigger just at the right moment. Thusno more code modification is needed and the setup is pretty simple.+ 
 +We need speedcode with predictable runlengths (so no random penalty cycles apply) to do soThe setup is quite simple and no code has to be restored
  
 All you need is setting up a IRQ/NMI handler once beforehand as the exit point of your routine, setup the timer with 2 writes to e.g. $dd04/$dd05 and start a single shot timer run by setting $dd0e to $09. All you need is setting up a IRQ/NMI handler once beforehand as the exit point of your routine, setup the timer with 2 writes to e.g. $dd04/$dd05 and start a single shot timer run by setting $dd0e to $09.
Line 94: Line 95:
  
 Regarding the cli instruction: This is important, as else normal irqs might be blocked until we restore the I-flag on the terminating rti, so find out for yourself if it is needed in your case. If so, you can just pull the original PC and flags from stack via pla/plp, instead of manipulating the stack pointer, or simply forgo on the cli if no further irq needs to happen. Regarding the cli instruction: This is important, as else normal irqs might be blocked until we restore the I-flag on the terminating rti, so find out for yourself if it is needed in your case. If so, you can just pull the original PC and flags from stack via pla/plp, instead of manipulating the stack pointer, or simply forgo on the cli if no further irq needs to happen.
- 
base/variable_speedcode_runlength.txt · Last modified: 2022-01-14 12:45 by bitbreaker