Less magic numbers in PIT code

This commit is contained in:
Jasmine Iwanek
2024-08-06 18:01:13 -04:00
parent 834bcd09c1
commit 837c16f546
4 changed files with 10 additions and 8 deletions

View File

@@ -19,6 +19,8 @@
#ifndef EMU_PIT_H #ifndef EMU_PIT_H
#define EMU_PIT_H #define EMU_PIT_H
#define NUM_COUNTERS 3
typedef struct ctr_t { typedef struct ctr_t {
uint8_t m; uint8_t m;
uint8_t ctrl; uint8_t ctrl;
@@ -68,7 +70,7 @@ typedef struct PIT {
int clock; int clock;
pc_timer_t callback_timer; pc_timer_t callback_timer;
ctr_t counters[3]; ctr_t counters[NUM_COUNTERS];
uint8_t ctrl; uint8_t ctrl;

View File

@@ -68,7 +68,7 @@ typedef struct ctrf_t {
typedef struct pitf_t { typedef struct pitf_t {
int flags; int flags;
ctrf_t counters[3]; ctrf_t counters[NUM_COUNTERS];
uint8_t ctrl; uint8_t ctrl;

View File

@@ -526,7 +526,7 @@ pit_timer_over(void *priv)
dev->clock ^= 1; 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); pit_ctr_set_clock_common(&dev->counters[i], dev->clock, dev);
timer_advance_u64(&dev->callback_timer, dev->pit_const >> 1ULL); timer_advance_u64(&dev->callback_timer, dev->pit_const >> 1ULL);
@@ -874,7 +874,7 @@ pit_device_reset(pit_t *dev)
{ {
dev->clock = 0; 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]); ctr_reset(&dev->counters[i]);
} }
@@ -885,7 +885,7 @@ pit_reset(pit_t *dev)
dev->clock = 0; 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]); ctr_reset(&dev->counters[i]);
/* Disable speaker gate. */ /* Disable speaker gate. */

View File

@@ -670,7 +670,7 @@ pitf_reset(pitf_t *dev)
{ {
memset(dev, 0, sizeof(pitf_t)); 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]); ctr_reset(&dev->counters[i]);
/* Disable speaker gate. */ /* Disable speaker gate. */
@@ -683,7 +683,7 @@ pitf_set_pit_const(void *data, uint64_t pit_const)
pitf_t *pit = (pitf_t *) data; pitf_t *pit = (pitf_t *) data;
ctrf_t *ctr; 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->counters[i];
ctr->pit_const = pit_const; ctr->pit_const = pit_const;
} }
@@ -728,7 +728,7 @@ pitf_init(const device_t *info)
dev->flags = info->local; dev->flags = info->local;
if (!(dev->flags & PIT_PS2) && !(dev->flags & PIT_CUSTOM_CLOCK)) { 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]; ctrf_t *ctr = &dev->counters[i];
ctr->priv = dev; ctr->priv = dev;
timer_add(&ctr->timer, pitf_timer_over, (void *) ctr, 0); timer_add(&ctr->timer, pitf_timer_over, (void *) ctr, 0);