indigodarkwolf / box16

A fork of the official X16 emulator, converted to C++20 and with a bunch of features tweaked and added.
MIT License
41 stars 19 forks source link

Writing to VIA IFR doesn't clear the set bits #58

Closed Yazwh0 closed 1 year ago

Yazwh0 commented 1 year ago

When writing to IFR, it should clear any bits that are set in the write. (bar bit 7, which should be preserved)

image

This disables VIA interrupts, and then should clear the bits.

10 poke $9f0e, $7f 20 a=peek($9f0d) 30 print a 40 poke $9f0d, a 50 print peek($9f0d)

expected: image

Emulator: image

indigodarkwolf commented 1 year ago

Yeah, looking at a datasheet for the 6522, I'm not sure why Box16 implementation only respects bits 0 and 3, and then only under certain circumstances regarding the PCR.

Reading was appears to be a datasheet for an original C64's 6522, I think the idea comes from a table that only lists means of clearing IRQ flags by interacting with the chip subcomponent that fired the IRQ: image

This interpretation is supported by the documentation created by the person who wrote the current VIA implementation: https://ayce.dev/emptyx16.html#dh---ifr---interrupt-flags-register-rw image

This datasheet for the Rockwell 6522, however, specifically documents the ability to clear bits directly on the IFR register: image

And certainly, MAME's implementation appears to be the Rockwell interpretation. Your screencap also suggests the Rockwell version.

indigodarkwolf commented 1 year ago

So yeah, talking with the guy who implemented it, sounds like the implementation may be a misinterpretation of the docs.

@Yazwh0 Just to be clear: The photo of the expected behavior is real hardware, right? Do you know the specific model of 6522 that's using? Or does it come from an official prototype board?

indigodarkwolf commented 1 year ago

Should be fixed with https://github.com/indigodarkwolf/box16/commit/e635a782ec2bb89566b831de2adc6e07fef7a3d7