joncampbell123 / dosbox-x

DOSBox-X fork of the DOSBox project
GNU General Public License v2.0
2.64k stars 373 forks source link

8259 PIC emulation: Add Specially Fully Nested mode (especially for PC-98 mode) #1138

Open joncampbell123 opened 5 years ago

joncampbell123 commented 5 years ago

There is growing evidence that emulation problems (and the workaround) are related by the use of Specially Full Nested Mode on PC-98 (instead of Fully Nested Mode on IBM PC/XT/AT).

The difference appears to affect how the cascade interrupt works, which is why the "ignore cascade interrupt ISR" hack always resolves ISR problems with PC-98 games.

In Fully Nested Mode, if the slave pic fires an IRQ, the ISR needs to EOI the master AND the slave before any more interrupts from the slave are sent to the CPU.

In Specially Fully Nested Mode, the slave PIC can issue more interrupts even if the master cascade interrupt is in service (if they are higher priority than prior slave interrupts). ISRs must EOI the slave PIC, then read the ISR bitfield and (should) ack the master IF there are no more interrupts pending on the slave (confirmed behavior of some PC-98 games). Most PC-98 games appear to EOI the slave PIC without checking the ISR or bothering to EOI the master cascade interrupt, which according to the documentation should happen to work anyway.

This also means that if an IBM PC/XT/AT DOS game also switches on Specially Fully Nested Mode, the warning message in src/hardware/pic.cpp can be removed and the cascade IRQ hack can be enabled at that point (as some IBM PC games/demos are reported to do).

See also: https://www.eeeguide.com/block-diagram-of-8259-programmable-interrupt-controller/

joncampbell123 commented 5 years ago

This modification must be done carefully. In the ideal case, the "cascade ISR hack" can just be made into Specially Fully Nested Mode and the BIOS init / PIC startup code can just be set to switch on Specially Fully Nested Mode as part of startup in PC-98 mode.

But I want to do this carefully:

I'm careful about DOSBox-X implementing actual hardware behavior, rather than the DOSBox SVN approach of making it "good enough" to get games running.

joncampbell123 commented 5 years ago

See also:

https://github.com/joncampbell123/dosbox-x/issues/1134 https://github.com/joncampbell123/dosbox-x/issues/1112 https://github.com/joncampbell123/dosbox-x/issues/920 https://github.com/joncampbell123/dosbox-x/issues/106

cracyc commented 5 years ago

Verify on real PC-98 hardware how interrupts react in the default programmed mode

Booting the original firmware on mame shows the master being programmed with sfnm.