Lines Matching full:ti

49 static void mos6522_timer1_update(MOS6522State *s, MOS6522Timer *ti,
51 static void mos6522_timer2_update(MOS6522State *s, MOS6522Timer *ti,
130 static uint64_t get_counter_value(MOS6522State *s, MOS6522Timer *ti) in get_counter_value() argument
134 if (ti->index == 0) { in get_counter_value()
135 return mdc->get_timer1_counter_value(s, ti); in get_counter_value()
137 return mdc->get_timer2_counter_value(s, ti); in get_counter_value()
141 static uint64_t get_load_time(MOS6522State *s, MOS6522Timer *ti) in get_load_time() argument
145 if (ti->index == 0) { in get_load_time()
146 return mdc->get_timer1_load_time(s, ti); in get_load_time()
148 return mdc->get_timer2_load_time(s, ti); in get_load_time()
152 static unsigned int get_counter(MOS6522State *s, MOS6522Timer *ti) in get_counter() argument
157 d = get_counter_value(s, ti); in get_counter()
159 if (ti->index == 0) { in get_counter()
161 if (d <= (ti->counter_value + 1)) { in get_counter()
162 counter = (ti->counter_value - d) & 0xffff; in get_counter()
164 counter = (d - (ti->counter_value + 1)) % (ti->latch + 2); in get_counter()
165 counter = (ti->latch - counter) & 0xffff; in get_counter()
168 counter = (ti->counter_value - d) & 0xffff; in get_counter()
173 static void set_counter(MOS6522State *s, MOS6522Timer *ti, unsigned int val) in set_counter() argument
175 trace_mos6522_set_counter(1 + ti->index, val); in set_counter()
176 ti->load_time = get_load_time(s, ti); in set_counter()
177 ti->counter_value = val; in set_counter()
178 if (ti->index == 0) { in set_counter()
179 mos6522_timer1_update(s, ti, ti->load_time); in set_counter()
181 mos6522_timer2_update(s, ti, ti->load_time); in set_counter()
185 static int64_t get_next_irq_time(MOS6522State *s, MOS6522Timer *ti, in get_next_irq_time() argument
191 if (ti->frequency == 0) { in get_next_irq_time()
196 d = muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - ti->load_time, in get_next_irq_time()
197 ti->frequency, NANOSECONDS_PER_SECOND); in get_next_irq_time()
200 if (d <= (ti->counter_value + 1)) { in get_next_irq_time()
201 counter = (ti->counter_value - d) & 0xffff; in get_next_irq_time()
203 counter = (d - (ti->counter_value + 1)) % (ti->latch + 2); in get_next_irq_time()
204 counter = (ti->latch - counter) & 0xffff; in get_next_irq_time()
209 next_time = d + ti->latch + 1; in get_next_irq_time()
211 next_time = d + ti->latch + 2; in get_next_irq_time()
215 trace_mos6522_get_next_irq_time(ti->latch, d, next_time - d); in get_next_irq_time()
216 next_time = muldiv64(next_time, NANOSECONDS_PER_SECOND, ti->frequency) + in get_next_irq_time()
217 ti->load_time; in get_next_irq_time()
225 static void mos6522_timer1_update(MOS6522State *s, MOS6522Timer *ti, in mos6522_timer1_update() argument
228 if (!ti->timer) { in mos6522_timer1_update()
231 ti->next_irq_time = get_next_irq_time(s, ti, current_time); in mos6522_timer1_update()
233 timer_del(ti->timer); in mos6522_timer1_update()
235 timer_mod(ti->timer, ti->next_irq_time); in mos6522_timer1_update()
239 static void mos6522_timer2_update(MOS6522State *s, MOS6522Timer *ti, in mos6522_timer2_update() argument
242 if (!ti->timer) { in mos6522_timer2_update()
245 ti->next_irq_time = get_next_irq_time(s, ti, current_time); in mos6522_timer2_update()
247 timer_del(ti->timer); in mos6522_timer2_update()
249 timer_mod(ti->timer, ti->next_irq_time); in mos6522_timer2_update()
256 MOS6522Timer *ti = &s->timers[0]; in mos6522_timer1() local
258 mos6522_timer1_update(s, ti, ti->next_irq_time); in mos6522_timer1()
266 MOS6522Timer *ti = &s->timers[1]; in mos6522_timer2() local
268 mos6522_timer2_update(s, ti, ti->next_irq_time); in mos6522_timer2()
273 static uint64_t mos6522_get_counter_value(MOS6522State *s, MOS6522Timer *ti) in mos6522_get_counter_value() argument
275 return muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - ti->load_time, in mos6522_get_counter_value()
276 ti->frequency, NANOSECONDS_PER_SECOND); in mos6522_get_counter_value()
279 static uint64_t mos6522_get_load_time(MOS6522State *s, MOS6522Timer *ti) in mos6522_get_load_time() argument