Mac OS 9 Lives

Mac OS 9 Discussion => Mac OS 9, Hacks & Upgrades => Mac OS 9 on Unsupported Hardware => Topic started by: biggieshellz on March 01, 2023, 11:22:07 AM

Title: Taking another shot at onboard audio on a Mac Mini G4?
Post by: biggieshellz on March 01, 2023, 11:22:07 AM
I always had Macs as a kid.  I used to hang out on the 68kMLA forum when I was in high school.  Now I do Linux driver development for 5G telecommunications SoCs.  I recently bought a Mac Mini G4 to show my kids some of what I used to play with (after a clamshell iBook started to fall apart faster than I could fix it).  It’s amazing what folks here have done to get Mac OS 9 to run on this hardware.

Anyways, it’s frustrating AF that onboard audio does not work quite right with Mac OS 9, and I was wondering if this is something I could fix.

Resources I’ve found on this:

https://github.com/torvalds/linux/tree/master/sound/aoa — this is the Linux kernel driver for this sound hardware (Toonie in our case).  It looks like there is no hardware support for setting the volume — it’s just a DAC — so any system-wide volume control would have to take place in software.

https://vintageapple.org/inside_r/pdf/Sound_1994.pdf — chapter 6 shows how to build an audio component, and what capabilities and callbacks are exposed through one.

http://macos9lives.com/smforum/index.php/topic,4682.msg36250.html — this shows which built-in component is used for the Mac Mini’s audio, and gives some basic information on how to find that within the System file.

So as far as a basic plan of attack, here’s what I’m thinking:

(1) Figure out how to extract the existing ‘awgc’ audio component from the Mac OS 9.2.2 system file (would https://github.com/fuzziqersoftware/resource_dasm be the right way to do this?)

(2) Reverse-engineer it to figure out what’s going on currently.  (Would Ghidra work, or do people have a tool they like better for classic Mac OS stuff?)

(3) Modify the audio component and put it back in the system file.

Would this be a sane way to go about it?  Has anyone else worked on this and has more information to contribute?

Thanks!
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: ssp3 on March 01, 2023, 12:09:44 PM
Re. awgc No need to go to dasm etc. - ResEdit will do. It's in a thng resource. Actually, there are 3 items with awgc in them. But, doesn't the sound manager extension have to be modified too?
Another useful tool for fixing things is Resorcerer.

* Pics are from 9.0.4
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: biggieshellz on March 01, 2023, 04:35:14 PM
Thanks, that's helpful.  So how do I map from the 'thng' resource to the code that implements the component?  Is there an ID or something that I can follow?
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: ssp3 on March 01, 2023, 05:26:24 PM
The IDs are right in front of you, in all 3 pics. -20493, -20490, -20489, -16563 etc.  ;D
How are they mapped I don't know. Just poke around 'til you find out. Or read the manual.
Or maybe someone more knowledgable than me will chime in.
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: smilesdavis on March 01, 2023, 09:43:08 PM
while we are at it, implement Steinberg M.ROS into mac os 9 :D
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: biggieshellz on March 02, 2023, 07:17:19 AM
OK, I actually opened up the System file in Resorcerer, and for thng -20489, it says "the template for thng -20489 describes more data than has actually been found in this resource".  And it's listed as [PACK 63,23].  Under the PACK resources in the System file, I don't see 63 or 23.  Does anyone know what this refers to or how to find it?
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: IIO on March 02, 2023, 09:19:27 AM
(Would Ghidra work, or do people have a tool they like better for classic Mac OS stuff?)

has no PPC support & is most likely a total overkill here.

a simple debugger like macsbug will probably do. it is an INIT and will end up in your /system folder/extensions, and to disable it you just remove it and reboot.

but let´s first see if resedit and browsing the ASCII representation is enough to fix it.

Does anyone know what this refers to or how to find it?

from the wording it only means that the template could visually show you more than what is there.

i have never seen this message and have no idea if it can be safely ignored.

you might also see this message when the resource is wrong or empty or a resource´s  content or format uses a wrong resource class name, but who knows.
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: robespierre on March 02, 2023, 09:49:48 AM
The notes in Resorcerer about "[PACK 63,23]" are letting you know that the resource's ID (-20489) is in a special range reserved for "owned" resources. This is explained on page 16 of the Resorcerer manual, and on page 109 of Inside Macintosh Volume I.

Except that, the ID -20489 is not in that range as the books define it. [PACK 63,23] should be ID -4105. I would not put too much importance on this PACK business, it looks completely spurious. (PACK resources are used by the Package Manager for collections of common routines that are loaded on demand by _Packn traps. For example, the Binary/Decimal Conversion Package or the Transcendental Functions package. There doesn't seem to be any _Pack63 trap.)
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: ssp3 on March 03, 2023, 05:16:17 AM
Also worth noting is that, if you are going to go at Sound Manager extension or anything else that has PPC code in data fork, you will need some tool that can pull it apart in a meaningful way.
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: biggieshellz on March 03, 2023, 07:45:14 PM
OK, so for -20489, there's an 'nift' resource of the same number that's a PEF file that I can look at in Ghidra.  There's also an nlib -20919 that's I2SAudioPlugin that looks more promising.  FWIW, Ghidra seems to do OK with PEF files and PowerPC assembly.

For those of you who suggested MacsBug, I have a few questions.  (1) is it possible to use MacsBug early enough in the boot flow to step through when one of these sound components gets loaded?  And (2) how do I go about finding where the sound component was loaded so I can set a breakpoint in one of the handler functions?  For instance, let's say I wanted to set a breakpoint that would be hit when an application plays a sound, or (on my clamshell iBook where this works) when I mute the sound or change the volume.  Can I go off of a symbol name, for instance?  Or are components loaded at a particular location in memory?
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: ssp3 on March 04, 2023, 08:06:08 PM
I think you dropped into MacsBug by holding control key at the start-up, but I might be mistaken.
You can also try the attached extensions, but they are pretty old, so there is no guarantee that they will work on 9.2.2


http://macos9lives.com/smforum/index.php?topic=3565.0

https://wiki.preterhuman.net/Tips_and_Tricks_for_MacsBug

MacsBug Reference and Debugging Guide:
https://manualzz.com/download/44810039

https://vintageapple.org/macbooks/pdf/Debugging_Macintosh_Software_with_MacsBug_1991.pdf

Nice collection of books:
https://vintageapple.org/macprogramming/

The attached document is either in old Word 5 (?) format or rich text.
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: biggieshellz on March 22, 2023, 08:18:15 AM
A bit more progress on this.

I've attached two photos.  The first one is the audio GPIOs -- I will cross-correlate these with the Linux driver to see which is which.  The second one is the I2S sound.

Edit: the hex in the audio GPIOs is ASCII, and says "headphone-detect", "headphone-mute", and "amp-mute", respectively.

Also, I'm able to use ELN's AudExtR from this forum (Sound Manager with the code moved to the resource fork) in combination with MacsBug and BreakBefore to enter the debugger as the extension is loaded.  However, it looks like there is a bunch of relocation that's done before any of the code is executed.  Does anyone know how to figure out where the individual resources within the extension will be loaded, so I can set breakpoints?
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: biggieshellz on April 05, 2023, 06:15:33 PM
A bit more progress on this.  I've been using Ghidra to look at the individual drivers within AudExtR.  I ran into an issue opening a few of the resources, and ended up submitting a fix to Ghidra for opening PEF files: https://github.com/NationalSecurityAgency/ghidra/pull/5178

The trick to using Ghidra for Mac OS 9 PPC is this.  Use https://github.com/fuzziqersoftware/resource_dasm to split out the resources.  Then drag them into the Ghidra project and pick the 32-bit PowerPC for Mac OS X option.  What this does is tell Ghidra that r2 (which always points to the TOC) will never change.  Then, from the Register Manager window, pick r2, and double-click the first mapping and set it to apply everywhere, from addresses 0x0 to 0xffffffff.  Then re-analyze.  This allows Ghidra to figure out the strings.

As far as the calling convention and MacsBug, page 1-43 of https://vintageapple.org/inside_r/pdf/PPC_System_Software_1994.pdf is super helpful.  The parameters are passed through registers, and for pointer parameters, you can view memory at those addresses to see what was passed in or out.
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: teroyk on April 06, 2023, 01:48:54 AM
MacNosy and The Debugger might be useful tools for you:
http://www.jasik.com/index.html
Programmer visited this forum some years ago:
http://macos9lives.com/smforum/index.php/topic,3565.msg45312.html#msg45312
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: biggieshellz on April 06, 2023, 07:19:59 AM
MacNosy and The Debugger might be useful tools for you:
http://www.jasik.com/index.html
Programmer visited this forum some years ago:
http://macos9lives.com/smforum/index.php/topic,3565.msg45312.html#msg45312

I'd love to try it, but $100 seems really steep -- that's more than I paid for the Mac Mini!  And the note from macnosy says "The only lost feature may be the ability to debug INITs," which is what I'm trying to do.
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: ssp3 on April 06, 2023, 07:43:05 AM
You've mentioned in your first post that you work for some commercial(?) entity. Don't they have IDA in their toolbox? It deals with Mac's PPC code in data fork quite nicely.
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: biggieshellz on April 06, 2023, 09:20:23 AM
You've mentioned in your first post that you work for some commercial(?) entity. Don't they have IDA in their toolbox? It deals with Mac's PPC code in data fork quite nicely.

To contribute to own-time open source, I had to sign a form that says I'm not allowed to use company resources (even my email address) for it.  And anyway, only one team has access to that tool, and I'd have to follow up with them to get access to the license server and make sure I'm not using the licenses at the same time they need it.
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: ssp3 on April 06, 2023, 10:23:26 AM
There are official Win/Mac free or demo versions available. Not sure about Linux, though.
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: biggieshellz on April 06, 2023, 07:32:57 PM
As far as IDA, the free versions only support x64/x86.  The home version, which does support PowerPC, is $200.  And Ghidra seems to be working fine for my purposes anyway.

Does anyone happen to have source code for any Mac OS 9 audio component driver, just so I would have a framework to hack something together rather than modifying an existing driver?
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: rvense on April 07, 2023, 08:12:25 AM
I'd imagine Apple themselves might have published something like that, but I don't know which SDK exactly to go looking in.
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: biggieshellz on April 07, 2023, 06:49:34 PM
That was a super useful breadcrumb to follow.  I didn't know about the SDKs.  On Macintosh Garden, I found the Apple Developer Connection 1996, and the December issue (reference library) contains article #20 which contains an article on how to write a sound output component, along with some sample code.

Note that I had to open this on an old Intel MacBook Pro running Mojave; my usual M1 MacBook Pro on Ventura won't mount HFS.  Anybody know a way around this, for CD images and DMGs?
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: RossDarker on April 08, 2023, 02:06:52 AM
There are various tools that can dump the contents of an HFS image such as machfs and hfsutils, however using them is a little different to mounting the image.

There is hfsexplorer to mount images in its own Java interface. Haven’t actually used this one before, but it looks good - I’ll probably visit it some time.

I have a slightly different approach though.
I attach the image as a CD/Drive to Mac OS 9 in Qemu/UTM, then work with it from there.
Either all the files can be viewed in the Mac OS 9 environment, or if some files need to be transferred to the host, another image can be used - a raw image that will show as a hard disk in the emulator, but can be mounted fully natively in macOS too.

This might seem like a long approach, but after setting everything up for the first time, the emulators start up pretty quickly these days. It does also feel like the most native way to me.


It’s really great to see the audio issue being tackled. Hope it all works out well, and many thanks for your work.
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: biggieshellz on April 10, 2023, 12:40:32 PM
A few more updates here.  So looking at the Open Firmware screenshots I posted earlier, the only thing in the .properties for the sound device was "name pseudo-sound".  That doesn't match what the Linux driver expects.  So I reset Open Firmware (reset-nvram, set-defaults, and then reset-all) and found that the full device showed up, as AOAKeylargo and with the expected layout-id.  So something is happening where the OS 9 audio driver removes the sound device from the device tree.

As a test, I removed the Apple Audio Extension, and while the onboard output doesn't show up in the Sound preference panel any longer, sound output still works, and the Open Firmware sound device still ends up renamed after a reset.  So perhaps the sound driver built into the System file is doing this?

Also, any ideas on where to set a breakpoint so I'll drop into MacsBug when an application plays a sound?  I tried "tvb SndPlay" and it sets the breakpoint, but I never see it hit.
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: Daniel on April 10, 2023, 05:01:11 PM
I looked through the Component Manager documentation, and it seems that it really doesn't want to expose where to find the component. Thankfully, we have the source. Hopefully it isn't too outdated. If these struct definitions are still accurate, you can peek into the RegisteredComponentInstancePtr returned by OpenComponent and then grab its rtiEntry. From there, rtRoutine and/or rtRoutineHandle are probably where you want to look to get the entry point. You probably need to lock the handle in memory somehow so that it doesn't get moved around (Unless that gets done for you somehow?).
https://github.com/elliotnunn/supermario/blob/master/base/SuperMarioProj.1994-02-09/Toolbox/ComponentMgr/PrivateThingManager.h#L79-L112 (https://github.com/elliotnunn/supermario/blob/master/base/SuperMarioProj.1994-02-09/Toolbox/ComponentMgr/PrivateThingManager.h#L79-L112)
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: biggieshellz on April 15, 2023, 08:18:08 PM
After reading https://vintageapple.org/inside_r/pdf/Sound_1994.pdf some more, I found that I can hit TVect breakpoints at SndDoCommand and SndDoImmediate when I run an application that plays sound (Spin Doctor, for instance).  However, I can't single-step through what happens to try to figure out which sound output component is being used.  See the attached MacsBug screenshot -- I end up stuck with a bus error.  If I trace over some of the calls, I can go farther, but I still end up stuck eventually before I make it into a sound output component.

Any ideas what to do here?  Is this as a result of debugging in ROM, and if so, how do I skip over that?
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: dtekle on October 01, 2023, 07:06:08 AM
Hello guys, was there any progress on this issue since April 2023?
If no, what is the roadblock and can other people help on this?
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: joevt on October 02, 2023, 03:10:14 PM
I looked through the Component Manager documentation, and it seems that it really doesn't want to expose where to find the component. Thankfully, we have the source. Hopefully it isn't too outdated. If these struct definitions are still accurate, you can peek into the RegisteredComponentInstancePtr returned by OpenComponent and then grab its rtiEntry. From there, rtRoutine and/or rtRoutineHandle are probably where you want to look to get the entry point. You probably need to lock the handle in memory somehow so that it doesn't get moved around (Unless that gets done for you somehow?).
https://github.com/elliotnunn/supermario/blob/master/base/SuperMarioProj.1994-02-09/Toolbox/ComponentMgr/PrivateThingManager.h#L79-L112 (https://github.com/elliotnunn/supermario/blob/master/base/SuperMarioProj.1994-02-09/Toolbox/ComponentMgr/PrivateThingManager.h#L79-L112)
Some Component Manger related apps:
- "Things!" by Gary Woodcock/QuickTime™ Development Team
- "Fiendishthngs" (has source code) from Apple
- "Reinstaller3" Apple Computer QuickTime 4.0 SDK
- "Thing Detective" from Unthinkable Research
- "Thing Reporter" from Unthinkable Research (free)

I think I was using these when I was reverse engineering the planb (video input of Power Mac 8500, 8600, etc.) video digitizer QuickTime component from Mac OS 9 68K to port to PowerPC and Mac OS X.
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: ssp3 on October 02, 2023, 03:21:57 PM
Hi joevt!  :)
It would be extremely cool if you, with your knowledge, could look into this Mac Mini audio thing. If you have time, of course.
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: dtekle on October 03, 2023, 09:54:21 AM
I found a page for the Linux sound drivers for PowerMac which mentioned similar issues with the sound volume with the Toonie chip (Mac mini G4) which may be solved with a new driver "snd-aoa":  https://wiki.debian.org/PowerPC/SoundCards (https://wiki.debian.org/PowerPC/SoundCards).

In another thread, someone pointed to the fact that the patched ROM makes Mac OS 9 treating the Mac Mini G4 as a Cube which had no built-in amplifier for the sound volume because it was meant to run with special speakers (Apple Pro USB Speakers) which had itself the amplifier for sound: http://macos9lives.com/smforum/index.php/topic,2408.msg52465.html#msg52465 (http://macos9lives.com/smforum/index.php/topic,2408.msg52465.html#msg52465).
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: zefrenchtoon on October 03, 2023, 12:22:44 PM
Thanks to answer to my post @dtekle  :)


I've found the post talking about the "choice" of the Cube identifier in the modified ROM and it seems to confirm my worries as with another machine id, the sound was described as "coming out through speakers is either really loud or distorted".

http://macos9lives.com/smforum/index.php/topic,2408.msg30135.html#msg30135

Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: zefrenchtoon on October 03, 2023, 12:46:47 PM
I would be curious to test a ROM using the eMac machine code …  ;D

As we can see here, it seems to be close to the mini:

http://apple-history.com/compare/g4cube/mac_mini/emac_usb2/emac
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: dtekle on October 05, 2023, 06:22:55 AM
As far I can see the specs (http://apple-history.com/compare/g4cube/mac_mini/emac_usb2/emac (http://apple-history.com/compare/g4cube/mac_mini/emac_usb2/emac)) there could be some benefits but also some disadvantages by using the Gestalt of eMac vs G4 Cube:

eMac/2004:
+ almost identical specs to the Mac mini (same G4 processor PowerPC 7447, same GFX Radeon 9200, same ATA-100 interface, same WiFi)
+ no USB-amplified sound outputs
- original machine not able to boot Mac OS 9 natively
- slightly different audio output format (16bit vs. 24bit)
- eMac has audio input (is it a problem anyway?)
- different sound chipset ("Snapper" vs Mini's "Toonie")

The older eMac is maybe usable as base for ROM modding (instead using the Mac G4 cube), but there may be issues with the graphic card (can these be fixed with drivers?)

eMac/2002:
+ natively bootable with Mac OS 9
- hardware is one generation older (G4 7450, only ATA-66, older WiFI) (G4 cube's hardware is even older!)
- uses Nvidia GeForce2 as GFX instead of ATI Radeon

Can someone of the original ROM modder team have a look into creating a custon ROM from the eMac/2002 ROM? As far I know there exist already a ROM mod for the eMac/2004 in this forum.
Title: Re: Taking another shot at onboard audio on a Mac Mini G4?
Post by: zefrenchtoon on February 05, 2024, 07:55:40 AM
Hi!

Sorry to unearth this topic but I had a strange behaviour with my Mini this morning.

I needed sound output for a quick test so I (re)tried to use a cheap USB audio adapter.
Once I connected the adapter, I got System sounds (mainly the ones from the OS theme) but no "standard" sound (from Quicktime Player or by playing an Audio CD in iTunes).
So I tried to reboot but with the adapter already connected.
Now, I got sound from my adapter.

OK but what's new ?

The first time, when I connected the adapter, it appeared in the Sound control panel.
When I restarted the mini, no adapter visible in the Sound control panel.

Does anyone have an explanation ??

Also ...  the control panel kept the "Main volume" to 0 even if I had sound in my speakers.  O_o