Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mos6561 sound & misc improvements #39

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

nippur72
Copy link
Contributor

This PR implements several improvements on the mos6561 VIC chip as noted in #26 :

  • 4 bit DAC: by quickly changing the volume register, the VIC-20 can do a 4-bit digital audio. The change I made was simply to output the value 0.5f when a voice channel is silent (before it was 0.0f). The 0.5 value is what allows the volume register to "modulate" the output and produce a digital waveform.

  • viznut waveforms: the sound generators produce their square waves not by a simple bit flipping, but via an internal 8 bit shift register with feedback. As discovered by viznut/pwp, loading certain values on such register allows the creation of square waveforms whose duty cycles varies according to certain patterns. In this PR I've created that shift register (voice->sreg and noise->sreg)

  • noise generator: this PR implements correctly the noise generator as discovered by Lance Ewing from his reverse engineering work on the die shot of the chip. There is a 16 bit LFSR that in turn drives the shifting of noise->sreg at the positive edge of LSFR's bit 0.

  • counter bug: the frequency counting was not correctly implemented: POKE 36874, 255 was higher in pitch than POKE 36874, 254 differently from a real VIC-20. I fixed the counters, and also changed them to increment instead of decrement as in the real chip. I also introduced a divider_counter to properly drive the counting.

  • float output: the channels now have an output field that stores the current output value so that it's not recalculated at each tick but only when the voice output changes.

@nippur72
Copy link
Contributor Author

UPDATE: I also fixed a bug in the Y-offset register: every unit in the register equals TWO lines not one. The screen geometry has to be adapted for this change as well. I tested the numbers on my CRT TV screen of a real VIC20 (in overscan mode).

@nippur72 nippur72 changed the title mos6561 sound improvements mos6561 sound & misc improvements Jul 20, 2020
@nippur72
Copy link
Contributor Author

UPDATE: I fixed two glitches occurring when the display was partially moved offscreen towards left or right.

When moved LEFT, the first 4 pixels were incorrect due to missing shift of vic->gunit.shift. I fixed it by always doing the shift, not just only in the visible area.

When moved RIGHT, the non visible part of the screen "wrapped" on the left side. I fixed it by going in border-mode when hcount reaches the right side limit. Since the vc updating is now halted when offscreen, I explicitly recalculate vc_base on every line.

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.

1 participant