VOGONS


SBEMU: Sound Blaster emulation on AC97

Topic actions

Reply 2060 of 2071, by jmarsh

User metadata
Rank Oldbie
Rank
Oldbie
ockiller wrote on 2026-11-27, 09:39:

Back on topic, at those ~400 MHz, Descent is a bit too fast, but playable, but sound is already playing at irregular speed, and so does the framerate/game speed. I haven't tried this with software based slowdown utilities to get in the optimal range for Descent but I suspect that sound will get even more irregular. That's why I wondered if a software based slowing down utility could have a mechanism to slow down code on a per-program basis. And I still use SBEMU too.

Have you tried just using the -640x480 command line switch for Descent? The higher resolution (and use of VESA) makes the game's framerate much more acceptable on faster machines.

Reply 2061 of 2071, by ockiller

User metadata
Rank Newbie
Rank
Newbie
jmarsh wrote on 2026-11-27, 10:43:

Have you tried just using the -640x480 command line switch for Descent? The higher resolution (and use of VESA) makes the game's framerate much more acceptable on faster machines.

I just tried it, after getting the v1.5 patch, and it's almost perfect! Thank you!
I need to target ~1 GHz for the music to play mostly at full speed. But the faster the CPU, the lower the mouse sensitivity is. 1 GHz is a good compromise.

Well, I can totally live with that and my idea is much less needed, but it could still improve the situation a bit further, in case someone has an idea whether it could be possible.

Reply 2062 of 2071, by DarthSun

User metadata
Rank Member
Rank
Member
ockiller wrote on 2026-11-27, 17:52:
I just tried it, after getting the v1.5 patch, and it's almost perfect! Thank you! I need to target ~1 GHz for the music to play […]
Show full quote
jmarsh wrote on 2026-11-27, 10:43:

Have you tried just using the -640x480 command line switch for Descent? The higher resolution (and use of VESA) makes the game's framerate much more acceptable on faster machines.

I just tried it, after getting the v1.5 patch, and it's almost perfect! Thank you!
I need to target ~1 GHz for the music to play mostly at full speed. But the faster the CPU, the lower the mouse sensitivity is. 1 GHz is a good compromise.

Well, I can totally live with that and my idea is much less needed, but it could still improve the situation a bit further, in case someone has an idea whether it could be possible.

I’ll give this a try. I didn’t even know it runs at 640...

The 3 body problems cannot be solved, neither for future quantum computers, even for the remainder of the universe. The Proton 2D is circling a planet and stepping back to the quantum size in 11 dimensions.

Reply 2063 of 2071, by Plombo

User metadata
Rank Newbie
Rank
Newbie

This week, I got back to thinking about “unreal mode” (a.k.a. flat real mode) games, and whether there’s a way to make them work with SBEMU. I’ve been reading the Pentium Pro manual, and it looks like there might be? But I will need some input from someone more knowledgeable than me.

From what I understand, addressing is the only meaningful difference between a task in V86 mode and a task in "normal" ring 3 protected mode. So, just like how the V86 system virtualizes 16-bit real mode with 16-bit ring 3 protected mode, it should be possible to virtualize a 32-bit real mode task with 32-bit ring 3 protected mode.

  • When a V86 task tries to enter unreal mode, instead of terminating it with a GPF like normal, switch the task into 32-bit protected mode with the same CPL/IOPL as the V86 task had. This gives it access to 32-bit addressing without breaking the model of 386 protected mode. It’s then handed over from the V86 monitor to the unreal monitor running within the same process. “Unreal monitor” is a term that I just made up, but it should be self-explanatory.
  • Just like a V86 monitor, the unreal monitor catches GPFs, and, when appropriate, emulates the instructions that caused them. The range of instructions emulated has to be different (and probably much harder to implement), though, since unreal mode can do things that ordinary 16-bit real mode can’t.
  • Interrupt handling and port trapping can be done on the ring 3 protected-mode task just like they would on a V86 task. This means the unreal mode program can work with SBEMU and other PCI sound drivers. (If it couldn’t, this entire exercise would be pointless.)

This all sounds simple enough when explained in a high-level overview like this, but the details add some complications. For one thing, the SMSW instruction is unprivileged [*], so a separate solution is needed to defeat the V86/protected mode detection that most unreal mode games have. Maybe there are some other unprivileged instructions that would also need to be patched or trapped with breakpoints. I don’t know.

So the question is, do any of those complications actually make it impossible to do? I haven’t found any such problem yet, but as someone who only recently started learning about how x86 stuff works, I’m not exactly an expert. So hopefully someone more knowledgeable can tell me either a) that this approach can work, or b) why it can’t.

[*] This is only mostly true. There actually is a CPU flag, CR4.UMIP, that makes SMSW generate a GPF in V86 mode and unprivileged protected mode. Unfortunately, that flag was first introduced in Ice Lake and Zen 2, less than 10 years ago! So most processors will need per-game patches or breakpoint lists for these instructions. However, it should be possible to generate either one automatically by running the game in an emulator and recording the locations of the relevant instructions.

Reply 2064 of 2071, by crazii

User metadata
Rank Oldbie
Rank
Oldbie

I don't think it's quite possible for an “unreal monitor”

let'ssay We can hack the mode switch and setup a protected mode client(dpmi env) for it and successfully hack Its interrupt handlers. the key problem is, the unreal mode is still in real mode. the addressing is different from protected mode. there is no way to map real mode segment to protected mode selectors because real mode segment has a increment of 1 for 16bytes aka 1 paragraph. but pm selector's minimal numerical increment is 8. the left 3 bits are RPL and LDT( TI aka table indicator).
I think you can talk to AI for possible solutions but I ain't thinking of any.

it might be possible If 4 selectors in gdt and another 4 in ldt to workaround the TI bit but the 2 RPL bit cannot overcome.

Toshiba Satellite Pro 4300 - YMF744, Savage IX
Toshiba Satellite 2805-S501 - YMF754, GeForce 2Go
IBM Thinkpad A21p - CS4624, Mobility Radeon 128
main: Intel NUC11PHKi7C Phantom Canyon: i7-1165G7 RTX2060 64G 2T760PSDD

Reply 2065 of 2071, by Plombo

User metadata
Rank Newbie
Rank
Newbie
crazii wrote on 2026-11-29, 14:40:
I don't think it's quite possible for an “unreal monitor” […]
Show full quote

I don't think it's quite possible for an “unreal monitor”

let'ssay We can hack the mode switch and setup a protected mode client(dpmi env) for it and successfully hack Its interrupt handlers. the key problem is, the unreal mode is still in real mode. the addressing is different from protected mode. there is no way to map real mode segment to protected mode selectors because real mode segment has a increment of 1 for 16bytes aka 1 paragraph. but pm selector's minimal numerical increment is 8. the left 3 bits are RPL and LDT( TI aka table indicator).
I think you can talk to AI for possible solutions but I ain't thinking of any.

it might be possible If 4 selectors in gdt and another 4 in ldt to workaround the TI bit but the 2 RPL bit cannot overcome.

I had to do some more reading about x86 and segments, but now I understand what you’re saying, and why non-V86 protected mode can’t emulate real-mode addressing.

As an aside, I’m not taking your suggestion to ask AI about it. Whenever I’m searching for semi-obscure technical information like this, Google always pops up with an (unwanted) AI answer, and about 75% of the time, that answer is completely wrong. If none of the AI’s training data contains a solution to the problem, and it does contain someone on a forum claiming it isn’t possible, the AI will usually just claim, with unearned total confidence, that the problem can’t be solved. It has no framework for actually creating novel solutions to novel problems. So AI is really not useful at all for things like this.

I haven’t given up, though. Instead, I’ve started thinking about it from another angle: is there any real need to switch the task out of V86 mode at all?

In any mode (protected, V86, even real mode), the processor raises a general protection fault on memory accesses whose effective address is outside of the segment limit. In protected mode, the segment limit is set by the descriptor table. In real and V86 mode, the segment limit is forced to 64 KB by the CPU. “Unreal mode” works around this in real mode by tricking the CPU into thinking the segment limit is the entire size of available memory, instead of 64 KB.

The segment limit trick doesn’t work in V86 mode, so accesses above 1 MB will always cause a general protection fault. But V86 monitors work in the first place by handling general protection faults! The “unreal monitor” knows where the memory access was supposed to go, and can access whatever memory it wants, so it can just run the instruction itself, just like V86 monitors do with I/O instructions and such.

Even better, since the application’s upper memory accesses are all routed through the monitor this way, the unreal monitor can do software-based virtual memory management. If the application tries to use an upper memory block that TSRs have been loaded into, the monitor can allocate any actually free block and transparently map the application’s accesses to that.

There is, of course, a significant performance cost to running an interrupt handler every time the application tries to access upper memory. But I doubt it matters much when factoring in the vastly greater speed of 21st-century CPUs compared to the humble 386/486 that “unreal mode” games were targeting.

This approach is really a lot simpler than the previous one, so I’m feeling better about its chances of working than I did with the first version. It does still have the same problem with SMSW being unprivileged, though, and will need the same solution.

Reply 2066 of 2071, by Plombo

User metadata
Rank Newbie
Rank
Newbie
Plombo wrote on 2026-11-29, 23:19:

Even better, since the application’s upper memory accesses are all routed through the monitor this way, the unreal monitor can do software-based virtual memory management. If the application tries to use an upper memory block that TSRs have been loaded into, the monitor can allocate any actually free block and transparently map the application’s accesses to that.

I can't edit my posts, so pretend this says "extended memory" instead of "upper memory". Maybe it was already obvious what I meant, since V86 mode can access upper memory (640 KB-1MB) just fine without any help from the monitor. This was talking about the memory after that 😀

Reply 2067 of 2071, by crazii

User metadata
Rank Oldbie
Rank
Oldbie

If you insist, and I think there might other ways around. the GP fault can be captured when a real mode segment is accessed and it can be replaced with a pm selector.
but it needs interpret some x86 instructions accessing segment directly (mov/push/pop - sounds simple, but think about mov es/ds/gs/fs, ax/bx/cx/dx... combinations, its not a simple opcode hard-test) or via segment prefix. Actually USBDDOS have that code to patch segments. Borland RTM the 16bit extender creates pm segment descriptors in its #GP handlers too, I don't know why, probably for compatibility reason or convenience (lazy creation).

and there's still cases if a rm segment collide with pm selectors (happens to be equal in value but in fact different base addresses) needs to be handle - there is no fault, just accessing the wrong memory.
overall it's full of hacks and breaks a lot of things, I don't think it's worth the effort, except that if you want do it with AI assistance.

Toshiba Satellite Pro 4300 - YMF744, Savage IX
Toshiba Satellite 2805-S501 - YMF754, GeForce 2Go
IBM Thinkpad A21p - CS4624, Mobility Radeon 128
main: Intel NUC11PHKi7C Phantom Canyon: i7-1165G7 RTX2060 64G 2T760PSDD

Reply 2068 of 2071, by RayeR

User metadata
Rank Oldbie
Rank
Oldbie

BTW I had a chance to test one Intel Mini-ITX motherboard D201GLY with Celeron 215 CPU and SiS964L southbrige and ADI1888 Soundmax codec that I repaired for a friend. VSBHDA don't detect audio codec. Last SBEMU for VDPMI does but no sound is routed out properly via codec. Unfortunatelly neither Mpxplay works. This was even tricky under Win98. First I searched for sound driver for SiS964L, found some, installed ok but no sound too. Then I found another driver package for ADI Soundmax (WDM driver for Win98 and 2k/XP) that finally worked. I belive the PCI part in SB works OK and only the AC'97 codec part is not properly configured to route sound out to jack. This MB has 3 jacks on backside for line in, line out and mic. PCI id is VEN_1039&DEV_7012. I can run some test version there but I will have to return it within a few days...

Gigabyte GA-P67-DS3-B3, Core i7-2600K @4,5GHz, 8GB DDR3, 128GB SSD, GTX970(GF7900GT), SB Audigy + YMF724F + DreamBlaster combo + LPC2ISA

Reply 2069 of 2071, by Angel Of Nemesis

User metadata
Rank Newbie
Rank
Newbie
CMR779 wrote on 2024-11-21, 22:03:

Does anyone else have any issues with the BOOM game in freedos? It's a version of Doom that uses the Allegro library. It seems to freeze while loading. I'm thinking it has something to do with allegro because the setup program, asetup.exe, doesn't want to run either. I've been able to run several other games just fine, and all the drivers and dll for sbemu loads without any problems. It seems to be some kind of memory issue.

Sorry if this issue has been addressed before, but this thread has gotten pretty long.

Yes, I have the same problem. Boom port freezes on the sound initialization when launched. Аsetup doesn’t want to work either.

Reply 2070 of 2071, by Plombo

User metadata
Rank Newbie
Rank
Newbie
crazii wrote on Yesterday, 05:31:
If you insist, and I think there might other ways around. the GP fault can be captured when a real mode segment is accessed and […]
Show full quote

If you insist, and I think there might other ways around. the GP fault can be captured when a real mode segment is accessed and it can be replaced with a pm selector.
but it needs interpret some x86 instructions accessing segment directly (mov/push/pop - sounds simple, but think about mov es/ds/gs/fs, ax/bx/cx/dx... combinations, its not a simple opcode hard-test) or via segment prefix. Actually USBDDOS have that code to patch segments. Borland RTM the 16bit extender creates pm segment descriptors in its #GP handlers too, I don't know why, probably for compatibility reason or convenience (lazy creation).

and there's still cases if a rm segment collide with pm selectors (happens to be equal in value but in fact different base addresses) needs to be handle - there is no fault, just accessing the wrong memory.
overall it's full of hacks and breaks a lot of things, I don't think it's worth the effort, except that if you want do it with AI assistance.

I don't think I understand what you're saying here. It reads more like a reply to my first post than the second one. If the monitor keeps the task running in V86 mode to emulate real mode, there should be basically 3 categories of GPFs from an "unreal mode" program:

  1. GPFs that would happen in any V86 mode program, and are handled through the existing V86 monitor like usual
  2. GPFs caused by special instructions in the "unreal mode" activation itself: loading the segment descriptor table, switching to protected mode, and switching back to real mode
  3. GPFs caused by accessing extended memory, like I described in my previous post

The real mode segment access problem can be fully solved by just leaving the task in V86 mode, like I described in my last post. The Unless I'm misunderstanding how it works, after an "unreal mode" program switches back to real mode, it goes back to using real mode addressing, bypassing the protected mode segment table. Real mode, unreal mode, and V86 mode all use (segment*16+offset) addressing for conventional memory. No fault is generated, and none is needed, because it will access the correct memory. "Unreal mode" is only different in that it can also use that (segment*16+offset) addressing for extended memory. And those accesses will always cause faults, so the monitor can get the physical address by doing the (segment*16+offset) calculation with the V86 task's registers on the stack.

That really just leaves the extended memory accesses as the only GPFs that would require real effort for an "unreal monitor" to handle:

  • Decode the opcode and operands of the instruction. This is just disassembling the instruction, and tons of people have written x86 disassemblers before. It might take some effort, but there's no question that it's possible.
  • Read memory for source operands (if any). It's not hard for the monitor to calculate where the accesses for an instruction are supposed to go.
  • Emulate the instruction. This is the "hard" part, because you have to get the side effects (flags) right. But I can think of two ways to make it not too much effort:
    • Repurpose the x86 emulation of an existing program like DOSbox or something. Copy in the registers from the V86 task's stack, run 1 instruction, write the flags+destination register back to the V86 task.
    • Or, even better, "reassemble" the instruction without the memory accesses, run it in the monitor, and write the flags+destination register back to the V86 task. This prevents the extra code bloat from the first option, and is probably simpler.
  • Write memory if the destination operand is an address.

This would all take some amount of implementation effort, but lots of things in SBEMU (and probably VDPMI) are similarly complicated. Right now, I'm still more focused on whether it's possible. I suspect there are at least 15 or 20 "unreal mode" games out there. Is it possible to make those games work with SBEMU, and play them on machines without ISA sound cards? I think that's a question worth answering, so I'm trying to figure it out.

Anyway, it's fine if you don't want to implement it yourself, but I don't think there's any reason to say things like "it's not worth doing except with AI assistance". Retrocomputer coding projects are hobby projects; even the more "useful" ones like SBEMU exist mostly for us to have fun making them. What's the point in getting a machine to do your hobby for you? If it's not worth doing properly, I think it's better to just not do it.

Reply 2071 of 2071, by RayeR

User metadata
Rank Oldbie
Rank
Oldbie

AFAIK as I it understood (maybe wrong), apps that use unreal mode do the RM-PM-RM switch only once at startup and rely on CPU descriptor cache will holds the right values set in PM for the rest of running. If V86 mon activates it reloads GDT with it's own setup then it would need to set it back for the app.

Gigabyte GA-P67-DS3-B3, Core i7-2600K @4,5GHz, 8GB DDR3, 128GB SSD, GTX970(GF7900GT), SB Audigy + YMF724F + DreamBlaster combo + LPC2ISA