Skip to content

Commit

Permalink
PIT: Make sure the new counter value is returned as written even if w…
Browse files Browse the repository at this point in the history
…ritten while the gate is off. This fixes [#4467]
  • Loading branch information
joncampbell123 committed Sep 24, 2023
1 parent 538e411 commit 197e598
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ Next version:
drive letter.
- Fix debugger to use toupper(), but only for ASCII range ncurses
keycodes.
- Timer PIT: If the guest writes the counter value while the counter
gate is off, make sure the counter read back is the same value
written regardless of gate status. Prior code returned the stale
latched value of the counter as it was prior to shutting off the
gate and writing the counter, causing timing issues.

2023.09.01
- Disable by default message confirmation after snapshot and AVI video
Expand Down
16 changes: 16 additions & 0 deletions src/hardware/timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ struct PIT_Block {

cntr_cur = new_cntr;
delay = ((pic_tickindex_t)(1000ul * cntr_cur)) / PIT_TICK_RATE;

/* Make sure the new counter value is returned if read back even if the gate is off!
* Some games like to constantly reprogram PIT 2 with precise event timey stuff and
* might shut the PC speaker PIT gate off during that time.
*
* Previous versions of this code failed to update the last_counter value when the
* game wrote a new counter and the PIT gate was off, causing the game to read back a
* stale counter value that was wrong.
*
* This fixes "Tony & Friends in Kellogg's Land" which does some rather weird elaborate
* timing stuff with both PIT 0 (timer) and PIT 2 (PC speaker but the output is off) to
* do it's event timing and to modify the VGA DAC mask mid-frame precisely to do that
* effect of making the bottom half look like there is water.
* Ref: [https://github.com/joncampbell123/dosbox-x/issues/4467] */
last_counter.cycle = 0;
last_counter.counter = cntr_cur;
}
void latch_next_counter(void) {
set_active_counter(cntr);
Expand Down

0 comments on commit 197e598

Please sign in to comment.