Skip to content

Commit

Permalink
Fix TCNT0 write behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiusbrown committed Mar 15, 2024
1 parent 9c3b8eb commit 38f0586
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/absim.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ struct atmega32u4_t
timer8_t timer0;
static void timer0_handle_st_regs(atmega32u4_t& cpu, uint16_t ptr, uint8_t x);
static void timer0_handle_st_tifr(atmega32u4_t& cpu, uint16_t ptr, uint8_t x);
static void timer0_handle_st_tcnt(atmega32u4_t& cpu, uint16_t ptr, uint8_t x);
static uint8_t timer0_handle_ld_tcnt(atmega32u4_t& cpu, uint16_t ptr);
void update_timer0();

Expand Down
1 change: 1 addition & 0 deletions src/absim_reset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ void atmega32u4_t::reset()

for(int i = 0x44; i <= 0x48; ++i)
st_handlers[i] = timer0_handle_st_regs;
st_handlers[0x46] = timer0_handle_st_tcnt;
for(int i = 0x80; i <= 0x8d; ++i)
st_handlers[i] = timer1_handle_st_regs;
for(int i = 0x90; i <= 0x9d; ++i)
Expand Down
8 changes: 8 additions & 0 deletions src/absim_timer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,14 @@ uint8_t atmega32u4_t::timer0_handle_ld_tcnt(atmega32u4_t& cpu, uint16_t ptr)
return cpu.data[ptr];
}

void atmega32u4_t::timer0_handle_st_tcnt(atmega32u4_t& cpu, uint16_t ptr, uint8_t x)
{
cpu.update_timer0();
cpu.data[ptr] = x;
cpu.timer0.tcnt = x;
cpu.update_timer0();
}

ARDENS_FORCEINLINE void atmega32u4_t::update_timer1()
{
update_timer16(*this, timer1);
Expand Down

0 comments on commit 38f0586

Please sign in to comment.