Closed joncampbell123 closed 8 years ago
I replicated your result for JUICE. There were no unhandled accesses logged; also, the init code is not available. :)
I have a dosbox-x build from last June and the gus audio works in the case of JUICE. I assume this is because the emulation was improved since then (and my gus.cpp didn't have 'force enable irq' code). The NO demo shows an error about an unhandled interrupt, but that must be from the same reason. The recent code shows the same as the OP except for NO which doesn't send the reset (probably I'm missing a code bit).
I checked over NO.EXE again, some of the unhandled I/O reported by DOSBox-X makes me think it supports and checks for the Gravis UltraMAX. I'm also seeing I/O writes to supposedly readonly registers. Hm...
I/O ports 0x34C-0x3CF are documented to be UltraMAX registers.
12404726 WARN IO:Writing 05 to port 034F <- UltraMAX ??
12404730 WARN IO:Writing 08 to port 0340 <- MIDI control (DOSBox/DOSBox-X does not emulate GUS MIDI controller)
12404734 WARN IO:Writing 00 to port 034B <- ??
It's also writing additional unknown registers
12408254 WARN IO:Writing 00 to port 024F <- ??
12408265 WARN IO:Writing 80 to port 024E <- ??
12408268 WARN IO:Writing 39 to port 024D <- ??
I booted up the Pentium and poked at the GUS Classic with DEBUG.EXE. Here's what I found:
In the reset register (select port 0x4C) bits 0-2 do exist (bits 3-7 do not exist).
Contrary to DOSBox-X emulation, the 8-bit GUS RESET register is accessible from both 3X4 and 3X5 (both halves of the 16-bit register I/O). However, writing to 3X4 has no effect.
I/O port 3X3 (Select) is documented for writing, but undocumented behavior for reading is different. I/O port 3X3 when read back seems to return the last byte value you wrote to ports 3X3-3X5, or the last byte value you read from 3X4-3X5.
If you write register 0x4C (GUS reset), and you transition bit 0 from 0 to 1 (taking the card out of reset), bits 1-2 are ignored. That means, if you select the GUS reset register, write 0x00, then write 0x07, then read it back, you'll get the value 0x01 instead. But once the card is taken out of reset, writing 0x07 sets all three bits as expected and you'll read back 0x07.
That rules out any possibility of merely resetting the card by reading and flipping a bit, because the other two bits are lost coming out of reset.
I also poked at registers 2X8-2XF. Despite lack of documentation on these ports in the GUS SDK, there are definitely ports there. Some of them I understand some of them are for SBOS to fake Sound Blaster ports via NMI, but I'm not sure how yet.
I just noticed the card is apparently an UltraMAX, not a GUS classic. The Ultrasound tools set up a ULTRA16 environment variable and there do exist ports 3XC-3XF.
I just ran JUICE.EXE and NO.EXE on the real hardware, and they seem to initialize the GUS just fine, no problems there.
So the next logical step I can think of is to start developing an Ultrasound test program/library in DOSLIB the same way I did for Sound Blaster, so I can tinker with the card and see what happens when you turn on/off certain bits.
It seems like a card made for the true enthusiast. I recall reading that it even has mt32 emulation in addition to others. Your findings are a very interesting development for expanding the audio emulation.
Edit: I reproduced the above results and I think theory 2 seems very reasonable! Do any demos break where bits 1-2 are "sticky"?
I just confirmed bits 1-2 are not sticky. I poked at the GUS UltraMax in my old Pentium and bits 0-2 are writable, while bits 3-7 are not (stuck at zero). What was not expected is that bits 1-2 are zeroed when bit 0 is changed (either to zero to reset, or 1 to clear reset).
That's surprising since I had guessed that the above remaining options/possibilities weren't as likely (3 and 4), since the demoscene must have a mix of GUS card types where a "bug" would be noticed and possibly commented on at their site.
I have an update on emulation.
I've been doing some poking around with GUS support in DOSLIB all night, and I was able to another theory of mine which turns out to be true:
Bit 2 of the reset register (select 0x4C) is called "Master IRQ Enable", but it's a "Master IRQ enable" for the voice/wave interrupts. The DMA terminal count interrupt is not affected by bit 2.
This is how NO.EXE is able to upload samples to GUS with DMA and an interrupt on completion, despite leaving the DAC disabled and the Master IRQ bit off.
Now we're making progress here. Playing with the GUS on real hardware shows the Adlib timers are also not affected by the Master IRQ Enable. This explains how Juice is able to play music without enabling the Master IRQ Enable.
So, what Gravis means by "Master IRQ Enable" is that it's a master enable for the wavetable/voice IRQs on the chip, not a master enable for ALL functions.
On a related note, I found documentation on the mysterious 2XA-2XF registers. Apparently when AMD acquired Gravis they bothered to document the hardware in a lot more detail than what Gravis alone provided. There's some fun stuff in that range regarding registers that trigger a NMI when written or read so that SBOS can fake a Sound Blaster and an Adlib FM synth.
Amazing improvements! Is it feasible to adapt your gus emulation to the SBOS system? Also, do you plan on uploading a youtube video in the near future which highlights some of the enhancements?
Running SBOS within DOSBox-X is a goal, yes. It would also allow the Ultrasound setup program's NMI test to pass. It's one of the reasons I added NMI emulation to the CPU. Then DOSBox-X could preserve for future generations just how horrible SBOS's Sound Blaster emulation really is :) Well, actually, it means DOSLIB might be able to provide an open source implementation of SBOS that doesn't suck so much.
I should really get to uploading some new videos. I just need to pick the "best of". There's not a whole lot of exciting stuff you can draw from a capture of the VGA output while I poke at I/O ports and test the latest compile over and over again.
The SBOS sounds very promising. I look forward to any developments on it.
I think your gus emulation and the dos box developments may be interesting to the community; for example, I assume warcraft2 won't enable gus for both sound and music on real hardware, yet it is now working in dosbox-x. However, the I/O port work is equally interesting to me, perhaps Hollywood teaches us that even a less exciting story can be peppered with a heavy dose of special visual/audio effects. :)
Does Warcraft 2 GUS support work on real hardware?
I don't have the real GUS to confirm whether it can be enabled for both sound and music at the same time (in warcraft 2). I assumed that your fix for that would apply to both emulation and real hardware.
GUS audio works for Juice and NO, even though "force master irq enable=false". NO didn't work until setting xms=true as indicated in your notes. :)
I don't recall the earlier build having with such excellent GUS music in Warcraft 2. With your most recent GUS emulation, I had to verify at least twice that General MIDI wasn't active instead because of the high quality output. Perhaps this is (partly) from the sample rate enhancement just added.
Go into the audio settings, and turn off the CD audio. The game will fall back to using the Gravis Ultrasound.
I don't have a CD loaded. :)
Good. Warcraft II defaulted to playing CD audio in my test setup, and I had to disable it to hear the actual GUS music.
A number of demos according to debug output seem to initialize the GUS as expected, but do not set the IRQ enable bit.
"No" by Nooon: Without the hack, the demo starts uploading samples to GUS RAM via DMA, but then hangs because it never set the IRQ enable bit, and it's waiting for a DMA TC interrupt that never arrives.
"Juice" by Psychic Link: Without the hack, music does not play.
The GUS reset register is arranged as follows according to the SDK:
In all cases, debug output shows the demos properly reset the GUS, but they never set the IRQ enable bit.
The thing is that, if DOSBox-X is correct, these demos should have failed at the demoparty either by hanging or by failing to play music. But they're well known demos in the scene, surely they initialized the GUS properly on real hardware, or music would not have worked.
Theories I have at the moment:
The Gravis SDK is wrong, and bits 1-2 never existed.The Gravis SDK is right, but bits 1-2 are "sticky" and cannot be cleared (once you enable the DAC and Master IRQ, the hardware doesn't let you turn them off again).The reset register is readable, DOSBox-X is not emulating read-back properly, and the demo's GUS support routines rely on reading and restoring bits 1-2 while flipping bit 0.So the task at hand is to pull out the old Pentium with the GUS and see which one of these theories is right (or if they're all wrong). I have on hand a GUS classic and a recently acquired GUS Interwave PnP to test against. Some new Ultrasound test code in DOSLIB would help as well. I'll dig in when spare time is available again.