Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIS 7012 support #27

Closed
thp opened this issue Sep 27, 2023 · 8 comments
Closed

SIS 7012 support #27

thp opened this issue Sep 27, 2023 · 8 comments

Comments

@thp
Copy link
Collaborator

thp commented Sep 27, 2023

Already posted on the Vogons thread, but here for completeness and to track progress:


While looking for information on SIS7012, I found (as also mentioned in this thread) that it's mostly Intel ICH with some modifications. As I have a machine with a SIS7012, and sound output works great in Linux, I looked at the kernel sources. The SIS7012 driver is indeed implement in the same driver as the Intel ICH (sound/pci/intel8x0.c), and MPXPlay's sources also mention that it's based on ALSA (Linux driver) and ICH-DOS.

So, a quick look shows these changes are necessary between SIS7012 and "normal" ICH audio (refer to sound/pci/intel8x0.c in Linux):

  • The channel mask bits (2, 4, 6 channels) in the global control block (register 0x2c) are different -- which is important for masking out the bits, but not important for setting bits, as SBEMU only uses 2-channel audio, and 2-channel audio is set by clearing the 4-channel and 6-channel bits -- that's ICH_PCM_246_MASK in both MPXPlay and Linux, Linux has the mask as ICH_SIS_PCM_246_MASK
  • SIS7012 supports a "tertiary" codec with two additional flags (tertiary resume irq, tertiary codec ready)
  • Linux assigns the device_type of DEVICE_SIS based on the PCI ID (MPXPlay has basically the same enum, the PCI ID is just commented out)
  • In snd_intel8x0_setup_pcm_out(), the channel mask setting is different (see above)
  • In snd_intel8x0_pcm_open(), both buffer_bytes_max and period_bytes_max are set to 64 KiB -- seems like we create smaller buffers anyway, so SBEMU is probably not affected by this
  • In snd_intel8x0_ich_chip_init(), the LSB of register 0x4c is set, and the comment above it says "unmute the output on SIS7012", which is probably kind of important..
  • Then, the ich_codec_bits[] has the tertiary for ICH4, but there's sis_codec_bits[] which has its own tertiary codec (ICH_SIS_TCR) bit
  • In snd_intel8x0_init(), bdbars is 3 for DEVICE_INTEL and also 3 for DEVICE_SIS, so this is probably fine
    SIS7012 swaps the PICB (position in current buffer, offset 0x08) and SR (status, offset 0x06) registers, this is put into "roff_sr" and "roff_picb" of the ichdev, and then used throughout; would need checking/updating to fix all the occurences and swap around
  • ichdev->pos_shift is 1 (divided by two) for normal ICH, and 0 (no division by two) for SIS7012, the comment above says "SIS7012 handles the pcm data in bytes, others are in samples" -- this also needs to be handled, and is mostly relevant in setting up DMA and when retrieving the PCM pointer (for writing?), there's also some reference to it in intel8x0_measure_ac97_clock(), but this seems to be only relevant for chips with a clock quirk
  • Then, when setting up max_codecs, codec_bit and codec_ready_bits, it also takes care of the tertiary codec, but it might work just fine with two codecs initialized (like normal ICH)
  • And that's all the differences I can see in sound/pci/intel8x0.c.

I already tried patching and building a modified SBEMU, and it initializes and stuff, but no audio output is happening and PCM audio output locks up or cannot be initialized (SB emu side), OPL register writes seem to work, but again no audio output. Add to this some annoyances such as upper/lower case filenames and backslashes as path separator in #include directives, and compiling SBEMU on Linux is quite annoying (I use a recent DJGPP version to cross-compile on Linux).

Also, here's some debug output I get with my modified SBEMU (due to testing, some messages might not 100% match with the patch attached):

SBEMU: Sound Blaster emulation on AC97. Version: 1.0 beta3
Hello, world! device_type = 3
00:00:00.000 sc_ich.c      446 chip init : enable PCI io and busmaster
00:00:00.164 sc_ich.c      486 vend_id:1039 dev_id:7012 devtype:SIS7012 bmport:EA00 mixport:E000 irq:10
00:00:00.164 sc_ich.c      207 buffer init: pagetable:00100000 pcmoutbuf:00100100 size:4096
00:00:00.164 sc_ich.c      215 clear status bits
00:00:00.164 sc_ich.c      220 ACLink ON, set 2 channels
00:00:00.164 sc_ich.c      226 AC97 reset type: cold
00:00:00.164 sc_ich.c      235 AC97 reset timeout:1000
00:00:00.164 sc_ich.c      239 primary codec reset timeout:1000
00:00:00.164 sc_ich.c      250 unmute the output on SIS7012
00:00:00.164 sc_ich.c      255 chip init end
00:00:00.164 sc_ich.c      278 ac97 init end (vra:0)
Found sound card: ICH AC97
Real mode support: enabled.
Protected mode support: enabled.
OPL3 emulation enabled at port 388h.
Sound Blaster Pro emulation enabled at Adress: 220, IRQ: 7, DMA: 1
00:00:00.164 sc_ich.c      286 prepare playback: period_size_bytes:1024
00:00:00.164 sc_ich.c      294 dma stop timeout: 1000
00:00:00.164 sc_ich.c      301 dma stop timeout: 1000
00:00:00.164 sc_ich.c      311 unmute the output on SIS7012
00:00:00.164 sc_ich.c      340 AC97 front dac freq:48000 
00:00:00.164 sc_ich.c      375 prepare playback end

WIP patch that doesn't work attached (I can turn this into a pull request once it starts working somewhat): sis7012-wip.patch

@thp
Copy link
Collaborator Author

thp commented Sep 27, 2023

Ok, so i shortly had audio output working in two situations now (with Duke3D demo, the intro FM synth music + the sound effects, and once with just the FM synth music, as SFX was disabled in setup then), but not sure what I did, and once the main menu was loaded, there was no more sound.

It's also hard to reproduce, after a cold boot it usually doesn't work, but sometimes it does - once, and often it just doesn't output anything.

New patch + test EXE attached (use at your own risk, etc. etc).

sis7012-wip-v2.zip

@thp
Copy link
Collaborator Author

thp commented Sep 27, 2023

@thp
Copy link
Collaborator Author

thp commented Sep 27, 2023

WIP code now here (still not working properly, only spuriously and for short periods):

https://github.com/thp/sbemu/tree/sis7012

@thp
Copy link
Collaborator Author

thp commented Sep 30, 2023

Proposed PR: #29

@q741451
Copy link

q741451 commented Oct 10, 2023

sis7012-wip-v2.zip

I tested it on my HP T5720, and the sound was successfully produced under MS-DOS!

@thp
Copy link
Collaborator Author

thp commented Oct 17, 2023

I tested it on my HP T5720, and the sound was successfully produced under MS-DOS!

Cool! Could you also test the build here to see if it also works? It cleans up some things that the "wip-v2" version doesn't have yet: https://github.com/thp/sbemu/releases/tag/1.0beta3-sis7012

@hjnijlunsing
Copy link

Very interesting! Would the same modifications also work on the M5455 as found in some HPT5710?

LSPCI: 00:04.0 Multimedia audio controller: ULi Electronics Inc. M5455 PCI AC-Link Controller Audio Device (rev 10)
This is based on the same Intel ICH; and here see them both mentioned together:
From: https://www.vogons.org/viewtopic.php?t=93006&start=620
"The ALi M5455 and SiS 7012 ICH-compatible audio controllers are not supported, apparently needs some extra code."

And also both seem to be using the same intel8x0.c in Linux

@thp
Copy link
Collaborator Author

thp commented Oct 20, 2023

No, SIS 7012 support doesn't add ALI M5455 support, but you can use the Linux driver as a reference to add support.

@crazii crazii closed this as completed in 960d02f Nov 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants