On 8/24/21 12:09 PM, Finn Thain wrote:
> mos6522_read() and mos6522_write() may call various functions to determine
> timer irq state, timer counter value and QEMUTimer deadline. All called
> functions must use the same value for the present time.
>
> Signed-off-by: Finn Thain <[email protected]>
> ---
> hw/misc/mos6522.c | 51 +++++++++++++++++++++++++----------------------
> 1 file changed, 27 insertions(+), 24 deletions(-)
> @@ -123,20 +123,19 @@ static int64_t get_next_irq_time(MOS6522State *s,
> MOS6522Timer *ti,
> trace_mos6522_get_next_irq_time(ti->latch, d, next_time - d);
> next_time = muldiv64(next_time, NANOSECONDS_PER_SECOND, ti->frequency) +
> ti->load_time;
> -
> - if (next_time <= current_time) {
> - next_time = current_time + 1;
> - }
Maybe extract as an helper? Otherwise:
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
> return next_time;
> }
>
> static void mos6522_timer1_update(MOS6522State *s, MOS6522Timer *ti,
> - int64_t current_time)
> + int64_t now)
> {
> if (!ti->timer) {
> return;
> }
> - ti->next_irq_time = get_next_irq_time(s, ti, current_time);
> + ti->next_irq_time = get_next_irq_time(s, ti, now);
> + if (ti->next_irq_time <= now) {
> + ti->next_irq_time = now + 1;
> + }
> if ((s->ier & T1_INT) == 0 ||
> ((s->acr & T1MODE) == T1MODE_ONESHOT && ti->oneshot_fired)) {
> timer_del(ti->timer);
> @@ -146,12 +145,15 @@ static void mos6522_timer1_update(MOS6522State *s,
> MOS6522Timer *ti,
> }
>
> static void mos6522_timer2_update(MOS6522State *s, MOS6522Timer *ti,
> - int64_t current_time)
> + int64_t now)
> {
> if (!ti->timer) {
> return;
> }
> - ti->next_irq_time = get_next_irq_time(s, ti, current_time);
> + ti->next_irq_time = get_next_irq_time(s, ti, now);
> + if (ti->next_irq_time <= now) {
> + ti->next_irq_time = now + 1;
> + }