@fmixolydian got me thinking about how to properly implement ::Run()
the problems i see are
- the ::Run() cycleMethod parameter seems like overkill (do we really anticipate flopping back and forth between the two modes on every call?)
- the existing ::Run and ::RunEternally means things will have to be maintained in multiple places (this bit me while working on the IRQ/NMI fixes)
what i would propose, in a future PR, would be to have there be THREE modes of operation.
the mode would be set in the constructor.
the modes would be INSTRUCTION, CYCLE, and OVERFLOW
combine the Run and RunEternally to be a single
int32_t Run(int32_t duration);
duration of -1 is special, it just means "run eternally" or a duration of "forever"
in INSTRUCTION mode, duration is in units of INSTRUCTIONS, ::Run() returns the number of instructions actually run
in CYCLE mode, duration is in units of CYCLES, ::Run() returns the number of cycles actually run.
in OVERFLOW mode, duration is also in units of CYCLES, but a cycleOverflow variable tracks excess cycles, and subtracts
that from the next ::Run() call. this is used to get @fmixolydian 's desired behavior. return value of ::Run in OVERFLOW mode will always be == duration. cycleOverflow is initialized to zero, and reset to zero on ::Reset()
i think this covers all the bases, simplifies the ::Run() method, and gives @fmixolydian the functionality they're after.
@fmixolydian got me thinking about how to properly implement ::Run()
the problems i see are
what i would propose, in a future PR, would be to have there be THREE modes of operation.
the mode would be set in the constructor.
the modes would be INSTRUCTION, CYCLE, and OVERFLOW
combine the Run and RunEternally to be a single
int32_t Run(int32_t duration);
duration of -1 is special, it just means "run eternally" or a duration of "forever"
in INSTRUCTION mode, duration is in units of INSTRUCTIONS, ::Run() returns the number of instructions actually run
in CYCLE mode, duration is in units of CYCLES, ::Run() returns the number of cycles actually run.
in OVERFLOW mode, duration is also in units of CYCLES, but a cycleOverflow variable tracks excess cycles, and subtracts
that from the next ::Run() call. this is used to get @fmixolydian 's desired behavior. return value of ::Run in OVERFLOW mode will always be == duration. cycleOverflow is initialized to zero, and reset to zero on ::Reset()
i think this covers all the bases, simplifies the ::Run() method, and gives @fmixolydian the functionality they're after.