Skip to content

Commit

Permalink
Merge pull request #14 from Kagamiin/fix/timer
Browse files Browse the repository at this point in the history
Fix bugs in timer implementation
  • Loading branch information
Kagamiin authored Feb 29, 2024
2 parents 26cc9bb + d33b655 commit ed1cba7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion esfm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2117,7 +2117,7 @@ ESFM_update_timers(esfm_chip *chip)
{
if (chip->timer_enable[i])
{
chip->timer_accumulator[i] += i == 0 ? TIMER1_CONST : TIMER2_CONST;
chip->timer_accumulator[i] += (i == 0) ? TIMER1_CONST : TIMER2_CONST;
if (chip->timer_accumulator[i] > 1.0)
{
chip->timer_accumulator[i] -= 1.0;
Expand All @@ -2126,6 +2126,7 @@ ESFM_update_timers(esfm_chip *chip)
{
if (chip->timer_mask[i] == 0)
{
chip->irq_bit = true;
chip->timer_overflow[i] = true;
}
chip->timer_counter[i] = chip->timer_reload[i];
Expand Down
15 changes: 11 additions & 4 deletions esfm_registers.c
Original file line number Diff line number Diff line change
Expand Up @@ -647,9 +647,11 @@ ESFM_write_reg_emu (esfm_chip *chip, uint16_t address, uint8_t data)
break;
case 0x02:
chip->timer_reload[0] = data;
chip->timer_counter[0] = data;
break;
case 0x03:
chip->timer_reload[1] = data;
chip->timer_counter[1] = data;
break;
case 0x04:
for (i = 0; i < 3; i++)
Expand Down Expand Up @@ -685,19 +687,24 @@ ESFM_write_reg_emu (esfm_chip *chip, uint16_t address, uint8_t data)
break;
case 0x02:
chip->timer_reload[0] = data;
chip->timer_counter[0] = data;
break;
case 0x03:
chip->timer_reload[1] = data;
chip->timer_counter[1] = data;
break;
case 0x04:
chip->timer_enable[0] = data & 0x01;
chip->timer_enable[1] = (data & 0x02) != 0;
chip->timer_mask[0] = (data & 0x20) != 0;
chip->timer_mask[1] = (data & 0x40) != 0;
if (data & 0x80)
{
chip->irq_bit = 0;
chip->timer_overflow[0] = 0;
chip->timer_overflow[1] = 0;
break;
}
chip->timer_enable[0] = data & 0x01;
chip->timer_enable[1] = (data & 0x02) != 0;
chip->timer_mask[1] = (data & 0x20) != 0;
chip->timer_mask[0] = (data & 0x40) != 0;
break;
case 0x08:
chip->keyscale_mode = (data & 0x40) != 0;
Expand Down

0 comments on commit ed1cba7

Please sign in to comment.