lc-3-2 / lc32sim

LC-3.2 simulator
0 stars 0 forks source link

Add High-Resolution Timer #30

Closed ammrat13 closed 1 year ago

ammrat13 commented 1 year ago

The timer is at REG_HIGHRESTIME_ADDR, and it's the number of milliseconds that have elapsed since the current second started.

Closes #29

sameer-s commented 1 year ago

LGTM, just a few questions/comments:

ammrat13 commented 1 year ago

LGTM, just a few questions/comments:

  • std::chrono::system_clock makes no guarantees about precision. However this should be ok in this case due to real-world behavior:
  • What exactly is the use-case? Is there a way we can get both the standard and high-res clocks in sync to get the "precise current time"?

I believe this can be dealt with by reading the milliseconds, then seconds, then milliseconds, then seconds. It's jank, but it should work. Still, it might be worth prettying up the interface to avoid this problem.

ammrat13 commented 1 year ago

A possible alternative interface is as follows. Have a timer status register along with the seconds and milliseconds register. The data registers are updated when anything is written to the status register.

sameer-s commented 1 year ago

Gotcha, well this should work for now as you described. Merging it in, but we might add a new interface later.