Author Topic: Taking another shot at onboard audio on a Mac Mini G4?  (Read 2071 times)

Offline biggieshellz

  • Valued Member (10+ Posts)
  • **
  • Posts: 12
  • New Member
  • Liked:
  • Likes Given: 0
Taking another shot at onboard audio on a Mac Mini G4?
« 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!

Offline ssp3

  • Gold Member (200+ Posts)
  • *****
  • Posts: 322
  • Liked:
  • Likes Given: 38
Re: Taking another shot at onboard audio on a Mac Mini G4?
« Reply #1 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
« Last Edit: March 01, 2023, 01:17:46 PM by ssp3 »
Expansion is non-negotiable.

Offline biggieshellz

  • Valued Member (10+ Posts)
  • **
  • Posts: 12
  • New Member
  • Liked:
  • Likes Given: 0
Re: Taking another shot at onboard audio on a Mac Mini G4?
« Reply #2 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?

Offline ssp3

  • Gold Member (200+ Posts)
  • *****
  • Posts: 322
  • Liked:
  • Likes Given: 38
Re: Taking another shot at onboard audio on a Mac Mini G4?
« Reply #3 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.
« Last Edit: March 02, 2023, 01:15:28 AM by ssp3 »
Expansion is non-negotiable.

Offline smilesdavis

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 651
  • New Member
  • Liked:
  • Likes Given: 17
Re: Taking another shot at onboard audio on a Mac Mini G4?
« Reply #4 on: March 01, 2023, 09:43:08 PM »
while we are at it, implement Steinberg M.ROS into mac os 9 :D
Looking for: Steinberg Cubase MAC Standard/Score v1-5 & Cubase Audio v1, Cubase Audio v2 for, Cubase Audio v3 for DAE/TDM => complete or in parts

Offline biggieshellz

  • Valued Member (10+ Posts)
  • **
  • Posts: 12
  • New Member
  • Liked:
  • Likes Given: 0
Re: Taking another shot at onboard audio on a Mac Mini G4?
« Reply #5 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?

Online IIO

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 4172
  • just a number
  • Liked:
  • Likes Given: 257
Re: Taking another shot at onboard audio on a Mac Mini G4?
« Reply #6 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.
insert arbitrary signature here

Offline robespierre

  • Enthusiast Member (25+ Posts)
  • ***
  • Posts: 86
  • malfrat des logiciels
  • Liked:
  • Likes Given: 11
Re: Taking another shot at onboard audio on a Mac Mini G4?
« Reply #7 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.)

Offline ssp3

  • Gold Member (200+ Posts)
  • *****
  • Posts: 322
  • Liked:
  • Likes Given: 38
Re: Taking another shot at onboard audio on a Mac Mini G4?
« Reply #8 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.
« Last Edit: March 03, 2023, 11:41:35 AM by ssp3 »
Expansion is non-negotiable.

Offline biggieshellz

  • Valued Member (10+ Posts)
  • **
  • Posts: 12
  • New Member
  • Liked:
  • Likes Given: 0
Re: Taking another shot at onboard audio on a Mac Mini G4?
« Reply #9 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?

Offline ssp3

  • Gold Member (200+ Posts)
  • *****
  • Posts: 322
  • Liked:
  • Likes Given: 38
Re: Taking another shot at onboard audio on a Mac Mini G4?
« Reply #10 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.
« Last Edit: March 04, 2023, 10:35:48 PM by ssp3 »
Expansion is non-negotiable.

Offline biggieshellz

  • Valued Member (10+ Posts)
  • **
  • Posts: 12
  • New Member
  • Liked:
  • Likes Given: 0
Re: Taking another shot at onboard audio on a Mac Mini G4?
« Reply #11 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?
« Last Edit: March 22, 2023, 08:10:08 PM by biggieshellz »

Offline biggieshellz

  • Valued Member (10+ Posts)
  • **
  • Posts: 12
  • New Member
  • Liked:
  • Likes Given: 0
Re: Taking another shot at onboard audio on a Mac Mini G4?
« Reply #12 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.

Offline teroyk

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 551
  • -
  • Liked:
  • Likes Given: 46
Re: Taking another shot at onboard audio on a Mac Mini G4?
« Reply #13 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
I bought my first new Mac when OS X 10.1 released. And I bought that Mac because it had Mac OS 9 too. And I bought my first 68k Mac when Apple stopped PPC Macs.

Offline biggieshellz

  • Valued Member (10+ Posts)
  • **
  • Posts: 12
  • New Member
  • Liked:
  • Likes Given: 0
Re: Taking another shot at onboard audio on a Mac Mini G4?
« Reply #14 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.

Offline ssp3

  • Gold Member (200+ Posts)
  • *****
  • Posts: 322
  • Liked:
  • Likes Given: 38
Re: Taking another shot at onboard audio on a Mac Mini G4?
« Reply #15 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.
Expansion is non-negotiable.

Offline biggieshellz

  • Valued Member (10+ Posts)
  • **
  • Posts: 12
  • New Member
  • Liked:
  • Likes Given: 0
Re: Taking another shot at onboard audio on a Mac Mini G4?
« Reply #16 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.

Offline ssp3

  • Gold Member (200+ Posts)
  • *****
  • Posts: 322
  • Liked:
  • Likes Given: 38
Re: Taking another shot at onboard audio on a Mac Mini G4?
« Reply #17 on: April 06, 2023, 10:23:26 AM »
There are official Win/Mac free or demo versions available. Not sure about Linux, though.
Expansion is non-negotiable.

Offline biggieshellz

  • Valued Member (10+ Posts)
  • **
  • Posts: 12
  • New Member
  • Liked:
  • Likes Given: 0
Re: Taking another shot at onboard audio on a Mac Mini G4?
« Reply #18 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?

Offline rvense

  • Veteran Member (100+ Posts)
  • ****
  • Posts: 107
  • Lombard & son
  • Liked:
  • Likes Given: 6
Re: Taking another shot at onboard audio on a Mac Mini G4?
« Reply #19 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.

Offline biggieshellz

  • Valued Member (10+ Posts)
  • **
  • Posts: 12
  • New Member
  • Liked:
  • Likes Given: 0
Re: Taking another shot at onboard audio on a Mac Mini G4?
« Reply #20 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?

Offline RossDarker

  • Gold Member (200+ Posts)
  • *****
  • Posts: 268
  • Liked:
  • Likes Given: 22
Re: Taking another shot at onboard audio on a Mac Mini G4?
« Reply #21 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.

Offline biggieshellz

  • Valued Member (10+ Posts)
  • **
  • Posts: 12
  • New Member
  • Liked:
  • Likes Given: 0
Re: Taking another shot at onboard audio on a Mac Mini G4?
« Reply #22 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.

Offline Daniel

  • Gold Member (200+ Posts)
  • *****
  • Posts: 300
  • Programmer, Hacker, Thinker
  • Liked:
  • Likes Given: 10
Re: Taking another shot at onboard audio on a Mac Mini G4?
« Reply #23 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

Offline biggieshellz

  • Valued Member (10+ Posts)
  • **
  • Posts: 12
  • New Member
  • Liked:
  • Likes Given: 0
Re: Taking another shot at onboard audio on a Mac Mini G4?
« Reply #24 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?

 


SimplePortal 2.3.6 © 2008-2014, SimplePortal