Skip to content

Improve Atari Lynx Mikey timer and audio accuracy - #157

Merged
ValleyBell merged 3 commits into
ValleyBell:masterfrom
drhelius:fix-mikey-timers
Aug 18, 2026
Merged

Improve Atari Lynx Mikey timer and audio accuracy#157
ValleyBell merged 3 commits into
ValleyBell:masterfrom
drhelius:fix-mikey-timers

Conversation

@drhelius

@drhelius drhelius commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Improve Mikey timer and audio behavior in the Atari Lynx audio core.

Changes

  • Store audio counter writes instead of ignoring them.
  • Treat RESET DONE as a level, so it clears TIMER DONE while set.
  • Trigger counter zero on the next input clock.
  • Stop completed one-shot timers until TIMER DONE is cleared.
  • Model clock selector 7 as a linked input instead of a fixed divider.
  • Implement the complete Timer 1/3/5/7 and Audio 0/1/2/3 borrow ring.
  • Handle CTLB software clocks and expose borrow, last-clock and timer-done status.
  • Reload counters and advance the audio LFSR only on terminal borrow.
  • Keep direct timers on a shared prescaler phase and service linked clocks in hardware order.
  • Catch up sub-sample timer events before returning generated audio.
  • Correct Lynx II stereo disable and attenuation routing.
  • Fix timer, audio, attenuation, pan and stereo register readback.
  • Keep LFSR state constrained to 12 bits and clamp the positive phase of volume $80.

These changes make timer state, linked clocks and audio output follow Lynx hardware behavior more closely.

This work is based on extensive hardware tests: https://github.com/drhelius/lynx-tests

There is a player implementation already using these changes here: https://www.drhelius.com/yawvgmp/

@drhelius
drhelius marked this pull request as draft August 16, 2026 17:43
@drhelius

Copy link
Copy Markdown
Contributor Author

Changed to draft to add more fixes, as I'm finding some more bugs, sorry about that.

@drhelius drhelius changed the title Fix Atari Lynx Mikey timer counter and reset behavior Improve Atari Lynx Mikey timer and audio accuracy Aug 16, 2026
@drhelius

Copy link
Copy Markdown
Contributor Author

There were indeed many issues with the current implementation. Now it's ready.

@drhelius
drhelius marked this pull request as ready for review August 16, 2026 23:40
Comment thread emu/cores/mikey.c
mikey_audio_sample_t sample;

if ( i >= samples )
return;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about the return here?
In that case, it will pop a queue action and then discard it without any further processing.

I'd expect the code to instead compare against the front of the queue (without popping) and only pop when the item gets processed.

@drhelius drhelius Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad.

mikey_action_queue_pop is misnamed: it doesn't remove or modify the selected entry.

It only scans mTab and returns the earliest timestamp and its stage.

If the output buffer is full, the return leaves the queue unchanged, so the next mikey_update() selects the same action again. The entry is only replaced after mikey_pimpl_fireStage() processes it.

The check is before generating another sample so that an event reached by the final sample in the block can still be processed before returning.

I can rename it to mikey_action_queue_peek and make the queue pointer const.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do that to reduce confusion. Thanks :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

@ValleyBell
ValleyBell merged commit 456b13b into ValleyBell:master Aug 18, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants