Difference between revisions of "Spice86"
(One intermediate revision by the same user not shown) | |||
Line 2: | Line 2: | ||
Additionally, one must give the parameter <code>--InstructionsPerSecond 5000000</code>. | Additionally, one must give the parameter <code>--InstructionsPerSecond 5000000</code>. | ||
− | <small>The reason for this workaround is that Stunts activates interrupts in the middle of the int 8 handler (see [https://github.com/4d-stunts/restunts/blob/89400488cf40086447a13afb19722225ee0ad094/src/restunts/asmorig/seg012.asm#L3727 here]), so another int 8 can could be triggered in between. This interrupt corresponds to the programmable interrupt timer, which Stunts [https://github.com/4d-stunts/restunts/blob/89400488cf40086447a13afb19722225ee0ad094/src/restunts/asmorig/seg012.asm#L3514 sets at 100 Hz]. So if the int 8 handler needs more than 1/100 seconds to run, disaster ensues. This | + | <small>The reason for this workaround is that Stunts activates interrupts in the middle of the int 8 handler (see [https://github.com/4d-stunts/restunts/blob/89400488cf40086447a13afb19722225ee0ad094/src/restunts/asmorig/seg012.asm#L3727 here]), so another int 8 can could be triggered in between. This interrupt corresponds to the programmable interrupt timer 8253-5 (AT: 8254.2), which Stunts [https://github.com/4d-stunts/restunts/blob/89400488cf40086447a13afb19722225ee0ad094/src/restunts/asmorig/seg012.asm#L3514 sets at 100 Hz]. So if the int 8 handler needs more than 1/100 seconds to run, disaster ensues. This probably never happens on real CPUs, but might occur if the emulator's simulated CPU is too slow with respect to the simulated PIT. |
Here a dump the relevant snippets, which should eventually go elsewhere | Here a dump the relevant snippets, which should eventually go elsewhere | ||
<pre> | <pre> | ||
− | seg012.asm-3514- mov dx, 2E9Ch ; Frequency for the PIT. 1193182 / 0x2e9c ~= 99.998 Hz | + | seg012.asm-3514- mov dx, 2E9Ch ; Frequency for channel 0 of the PIT. 1193182 / 0x2e9c ~= 99.998 Hz |
[...] | [...] | ||
− | seg012.asm-3555- mov al, 0B6h | + | seg012.asm-3555- mov al, 0B6h ; Set up PIT's channel 2 (PC Speaker). Unrelated, included for reference. |
− | seg012.asm:3556: out 43h, al ; | + | seg012.asm:3556: out 43h, al ; Set channel 2 to opmode = 3 (square wave) |
[...] | [...] | ||
− | |||
− | |||
seg012.asm-3582- mov al, dl | seg012.asm-3582- mov al, dl | ||
− | seg012.asm:3583: out 40h, al ; | + | seg012.asm:3583: out 40h, al ; Set PIT's channel 0 frequency, low byte (9C) |
seg012.asm-3584- mov al, dh | seg012.asm-3584- mov al, dh | ||
− | seg012.asm:3585: out 40h, al ; | + | seg012.asm:3585: out 40h, al ; Set PIT's channel 0 frequency, high byte (2E) |
-- | -- | ||
− | + | seg012.asm-3623- mov al, 0 ; Reset frequency to 1193182 / 65536 ~= 18.2 Hz | |
− | + | seg012.asm:3624: out 40h, al ; send low byte (0) | |
− | seg012.asm-3623- mov al, 0 ; Reset frequency to ~18 Hz | + | seg012.asm:3625: out 40h, al ; send high byte (0) |
− | seg012.asm:3624: out 40h, al ; | ||
− | seg012.asm:3625: out 40h, al ; | ||
</pre> | </pre> | ||
Latest revision as of 15:42, 1 March 2025
Spice86 is an experimental emulator, whose support for Stunts is being worked on as of 2025. At present (2025-03-01) it can start the game, but no sound is played (start with -a /ns
to avoid wasting cycles on that)
Additionally, one must give the parameter --InstructionsPerSecond 5000000
.
The reason for this workaround is that Stunts activates interrupts in the middle of the int 8 handler (see here), so another int 8 can could be triggered in between. This interrupt corresponds to the programmable interrupt timer 8253-5 (AT: 8254.2), which Stunts sets at 100 Hz. So if the int 8 handler needs more than 1/100 seconds to run, disaster ensues. This probably never happens on real CPUs, but might occur if the emulator's simulated CPU is too slow with respect to the simulated PIT.
Here a dump the relevant snippets, which should eventually go elsewhere
seg012.asm-3514- mov dx, 2E9Ch ; Frequency for channel 0 of the PIT. 1193182 / 0x2e9c ~= 99.998 Hz [...] seg012.asm-3555- mov al, 0B6h ; Set up PIT's channel 2 (PC Speaker). Unrelated, included for reference. seg012.asm:3556: out 43h, al ; Set channel 2 to opmode = 3 (square wave) [...] seg012.asm-3582- mov al, dl seg012.asm:3583: out 40h, al ; Set PIT's channel 0 frequency, low byte (9C) seg012.asm-3584- mov al, dh seg012.asm:3585: out 40h, al ; Set PIT's channel 0 frequency, high byte (2E) -- seg012.asm-3623- mov al, 0 ; Reset frequency to 1193182 / 65536 ~= 18.2 Hz seg012.asm:3624: out 40h, al ; send low byte (0) seg012.asm:3625: out 40h, al ; send high byte (0)
Relevant docs
- https://wiki.osdev.org/Programmable_Interval_Timer
- https://en.wikibooks.org/wiki/X86_Assembly/Programmable_Interval_Timer