by ferris
Ok, so apparently I've been working on this damn emulator for 8 weeks now! NUTS.
I spent a lot of the week debugging more of this timer stuff, including a little over 2 hours on the stream. And, what do you know - later found out it was all wrong!
Turns out I hadn't tested Vertical Force in awhile, because it still has some frustrating bugs. And when I did, I noticed it was running a bit fast. I double-checked against the hardware, and of course, it was. Adjusting the small timer interval back to the documented 20us interval fixed this. "yay". So that's a known at least, but a bummer that I went down such a rabbit hole assuming it might be wrong! I'm guessing now that the inaccuracy in the timer causing samples to play at the wrong rate is actually related to the CPU starting/stopping the timer with a bit bad timing, as the CPU is not cycle-accurate at the moment. Looks like one of the community members is taking a look at that though, so I expect it to shape up quite a bit in the next little while :)
I also did a bit of documentation for the project; particularly, I did a proper readme and some docs on how to contribute. I also started a discord server, where some interesting discussion has been going on, so that's rad!
Finally, I was testing Virtual Bowling again. It had what I thought were similar bugs to Vertical Force and Space Invaders, as they all started working around the same time and are still all slightly broken. However, when testing, I noticed something interesting.
Vertical Bowling's bugs were basically little "pauses" in the intro sequence and sometimes during gameplay. This was similar to some of the floating point bugs I saw really early on when implementing those CPU instructions related to rounding and round-tripping to integer values, so I thought these might be the same bugs. However, since we now have sound implemented, I noticed that whenever there was a pause, there was also a high-pitched hiss or garbled noise. A clue!!
As I often do for quick checks, I looked at a longplay of the game on youtube and noticed there were some bowling-ish sounds and vocal samples playing in the intro sequence that weren't on mine, and there also weren't the hissy pauses like mine was showing, either. Thinking they might be correlated, I started thinking about what might cause both the hissy pauses and the samples not to play, and it was obvious - those hissy pauses must be the samples playing super fast, instead of spread out over time!
From Galactic Pinball previously we saw that samples were being played by changing some audio registers quickly on timer ticks to play the samples from software. I also remembered that early on, I had issues getting the timer interrupt to be acknowledged properly with some games, resulting in the timer interrupt firing instantly when the interrupt was finished processing. If this were the case, we'd get all of the individual samples in the vocal sample playing at once instead of at the correct rate, which seemed to fit both the hissing and the pausing (because the game logic wouldn't continue in this case).
Turns out I was right. A quick check of the code and the documentation indicated that I was only ack'ing the timer interrupt in one of two possible scenarios - when the interrupt is disabled, but not when the zero status bit of the timer's control reg was explicitly marked zero as well. Seems Virtual Bowling was doing the latter, not the former, so this was a simple fix. This bumps up compatibility (by our metric) from 68% to 71%, so yay, quantifiable improvement!
Finally, I also looked a bit into getting binary distributions available for the emulator. Since we already use travis and appveyor for some free, simple CI, why not make those also build artifacts and upload those somewhere?
I searched around a bit and found trust, which is a great example of how to do this and works super well with github releases. I tried it out myself in isolation and it appears to work really well, so that's most of the technical bits solved! However, I also have to handle some annoying licensing stuff etc, so I asked about it in the Rust user's forum and while I didn't get much response, I was at least able to exhaustively list all of the project's dependencies, which was helpful. From there, I dug around in Cargo's installation dir to see how they were doing licensing for distribution, and found this license file. Using that as a model, I threw this one together, as well as a small readme that just points to our new website (which is up but I don't want to spread it yet until we have bin builds, so expect that next week) and the project repo. Next step is setting up the CI servers to pack up the right stuff, and we should be on our way. Again, the goal here is to get everything set up as MVP's and invite others to contribute, which I hope is a good strategy :)
And then I'll finally get on those last couple emulation features :)