Less magic numbers in PIT code
This commit is contained in:
@@ -19,6 +19,8 @@
|
||||
#ifndef EMU_PIT_H
|
||||
#define EMU_PIT_H
|
||||
|
||||
#define NUM_COUNTERS 3
|
||||
|
||||
typedef struct ctr_t {
|
||||
uint8_t m;
|
||||
uint8_t ctrl;
|
||||
@@ -68,7 +70,7 @@ typedef struct PIT {
|
||||
int clock;
|
||||
pc_timer_t callback_timer;
|
||||
|
||||
ctr_t counters[3];
|
||||
ctr_t counters[NUM_COUNTERS];
|
||||
|
||||
uint8_t ctrl;
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ typedef struct ctrf_t {
|
||||
|
||||
typedef struct pitf_t {
|
||||
int flags;
|
||||
ctrf_t counters[3];
|
||||
ctrf_t counters[NUM_COUNTERS];
|
||||
|
||||
uint8_t ctrl;
|
||||
|
||||
|
||||
@@ -526,7 +526,7 @@ pit_timer_over(void *priv)
|
||||
|
||||
dev->clock ^= 1;
|
||||
|
||||
for (uint8_t i = 0; i < 3; i++)
|
||||
for (uint8_t i = 0; i < NUM_COUNTERS; i++)
|
||||
pit_ctr_set_clock_common(&dev->counters[i], dev->clock, dev);
|
||||
|
||||
timer_advance_u64(&dev->callback_timer, dev->pit_const >> 1ULL);
|
||||
@@ -874,7 +874,7 @@ pit_device_reset(pit_t *dev)
|
||||
{
|
||||
dev->clock = 0;
|
||||
|
||||
for (uint8_t i = 0; i < 3; i++)
|
||||
for (uint8_t i = 0; i < NUM_COUNTERS; i++)
|
||||
ctr_reset(&dev->counters[i]);
|
||||
}
|
||||
|
||||
@@ -885,7 +885,7 @@ pit_reset(pit_t *dev)
|
||||
|
||||
dev->clock = 0;
|
||||
|
||||
for (uint8_t i = 0; i < 3; i++)
|
||||
for (uint8_t i = 0; i < NUM_COUNTERS; i++)
|
||||
ctr_reset(&dev->counters[i]);
|
||||
|
||||
/* Disable speaker gate. */
|
||||
|
||||
@@ -670,7 +670,7 @@ pitf_reset(pitf_t *dev)
|
||||
{
|
||||
memset(dev, 0, sizeof(pitf_t));
|
||||
|
||||
for (uint8_t i = 0; i < 3; i++)
|
||||
for (uint8_t i = 0; i < NUM_COUNTERS; i++)
|
||||
ctr_reset(&dev->counters[i]);
|
||||
|
||||
/* Disable speaker gate. */
|
||||
@@ -683,7 +683,7 @@ pitf_set_pit_const(void *data, uint64_t pit_const)
|
||||
pitf_t *pit = (pitf_t *) data;
|
||||
ctrf_t *ctr;
|
||||
|
||||
for (uint8_t i = 0; i < 3; i++) {
|
||||
for (uint8_t i = 0; i < NUM_COUNTERS; i++) {
|
||||
ctr = &pit->counters[i];
|
||||
ctr->pit_const = pit_const;
|
||||
}
|
||||
@@ -728,7 +728,7 @@ pitf_init(const device_t *info)
|
||||
dev->flags = info->local;
|
||||
|
||||
if (!(dev->flags & PIT_PS2) && !(dev->flags & PIT_CUSTOM_CLOCK)) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int i = 0; i < NUM_COUNTERS; i++) {
|
||||
ctrf_t *ctr = &dev->counters[i];
|
||||
ctr->priv = dev;
|
||||
timer_add(&ctr->timer, pitf_timer_over, (void *) ctr, 0);
|
||||
|
||||
Reference in New Issue
Block a user