NASM直接访问声卡(无操作系统)

发布于 2024-08-14 00:18:58 字数 172 浏览 3 评论 0 原文

我正在尝试用 ASM 和 C 编写一个非常简单的操作系统。(NASM 汇编器) 我想直接访问声卡,无论有没有驱动程序。 如果我不需要驱动程序,我如何访问和发送示例音频文件 到声卡? (举个例子就好了) 如果我确实需要驱动程序,是否可以连接它们并调用函数 来自司机?以及如何访问示例音频文件并将其发送到 声卡? (另一个例子会很好)

I'm attempting to write a very simple OS in ASM and C. (NASM assembler)
I would like to access the sound card directly, with or without drivers.
If I don't need drivers, how could I access and send a sample audio file
to the sound card? (An example would be nice)
If I do need drivers, is there anyway to interface them and call functions
from the drivers? And how do I access and send a sample audio file to the
sound card? (Another example would be nice)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

天生の放荡 2024-08-21 00:18:58

我不想劝阻您,但现代声卡驱动程序非常复杂,并且您可能知道,特定于操作系统。这就是操作系统开发中的难题之一——驱动程序支持。这不是简单的代码片段就能实现的。

为了加载文件,您需要一个文件系统。你已经实施了吗?您使用“内核”标志的事实表明您的操作系统仍处于起步阶段。我不确定我是否愿意将健全的支持放入操作系统的内核中。

话虽这么说,有一个名为 Bochs 的优秀模拟器,它具有 Sound Blaster 16仿真。还有一些关于如何编程的非常旧的文档。这可能是您最好的选择。在当时,访问声音硬件要容易得多。

I hate to discourage you, but modern sound card drivers are extremely complicated, and as you probably know, OS-specific. This is one of the difficult challenges in OS development - driver support. It's not something that can be achieved with a simple code snippet.

In order to load a file, you need a file system. Have you implemented that yet? The fact that you used the "kernel" flag suggests that your OS is still in its infancy. I'm not sure I would want to put sound support into the kernel of an operating system.

That being said, there is a good emulator called Bochs that has Sound Blaster 16 emulation. And some really old documentation for how to program it. This might be your best bet. Accessing sound hardware was much easier back in the day.

巴黎夜雨 2024-08-21 00:18:58

您最好的选择可能是查看 Linux 或 FreeBSD 声音驱动程序,看看它们的作用。除了最简单的声卡之外,您不可能获得更好的实现文档......

这是一个难题。请注意:-p

Your best bet is probably to look at either the Linux or FreeBSD sound drivers and see what they do. You're not likely to get much better implementation documentation for any but the simplest sound card...

This is a hard problem. Be warned :-p

九命猫 2024-08-21 00:18:58

当然,您需要一个驱动程序,并且当然没有简单的方法来与现有驱动程序交互(有人提出了一些与操作系统无关的统一“统一驱动程序接口”的建议 - 但我认为它没有任何进展)。

因此,在编写从硬盘驱动器读取文件的代码后,您需要推出自己的音频驱动程序。

现在,我已经有一段时间没有这样做了,所以这可能已经过时了,但是在 90 年代,您可以使用一些“out dx, al”配置您的声卡(详细信息因声卡而异),然后将 DMA 设置为将数据从内存缓冲区发送到您的卡。当卡(或者是 DMA 控制器?)到达缓冲区末尾时,它会触发一个中断,您可以用它来用新数据填充缓冲区。

如果你的卡有一个可用的 Linux 驱动程序,我会首先查看它的代码。否则,您将不得不对 Windows 驱动程序进行逆向工程,Soft-Ice 的 bpio(io 端口访问中断)日志记录曾经非常适合该 iirc。

祝你好运。

Of course you need a driver, and of course there's no easy way to interface with existing ones (there was some proposal for a unified OS-agnostic "Uniform Driver Interface" - but I don't think it got anywhere).

So, after you've written the code to read a file from your hard drive, you'll need to roll your own audio driver.

Now, I haven't done this in a while, so this may be outdated, but in the 90's you'd configure your sound card with a few 'out dx, al' (details varied across soundcards), and then setup DMA to send data from a memory buffer to your card. The card (or was it the DMA controller?) would fire off an interrupt when it reached the end of the buffer, which you'd use to fill the buffer with new data.

If your card has a working linux driver I'd start by looking at its code. Otherwise, you'll have to reverse engineer the windows driver, Soft-Ice's bpio (break on io port access) logging used to be good for that iirc.

Good luck.

桜花祭 2024-08-21 00:18:58

这是一个用所有汇编语言编写的免费开源操作系统。如果您是汇编内核编程新手,那么这对于汇编内核编程来说是很好的参考。

http://www.menuetos.net/index.htm

Here is a free open-sourced operating system written in all assembly. It is great reference for assembly kernel programming if you are new to it.

http://www.menuetos.net/index.htm

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文