Programming my own Mac emulator

About DingusPPC, a powermac emulator in development

Moderators: Cat_7, Ronald P. Regensburg

kataetheweirdo
Master Emulator
Posts: 320
Joined: Sun Feb 01, 2009 4:55 pm

Programming my own Mac emulator

Post by kataetheweirdo »

I've been spending a good chunk of time learning how a PowerPC Mac works. While I still have a long way to go before it can even reach the boot screen, I've put in no small amount of effort into this.

Here is a link to the source code, if you want to give it a spin.
kataetheweirdo
Master Emulator
Posts: 320
Joined: Sun Feb 01, 2009 4:55 pm

Re: Programming my own Mac emulator

Post by kataetheweirdo »

So, the ROMs get a little farther, but it will be some time before it's ready.

Right now, at best, the emulator runs slightly faster than a PowerPC 601 at 60 MHz. And that's with an Intel Core i7. Needless to say, I'll need to optimize this some before progressing.

Also, dynamic memory mapping will be needed as this is aiming toward multiple Old World Macs.
kataetheweirdo
Master Emulator
Posts: 320
Joined: Sun Feb 01, 2009 4:55 pm

Re: Programming my own Mac emulator

Post by kataetheweirdo »

With bit of a tweak, it now performs at slightly under 200 MHz. The change will be merged soon, along with another commit that will deal with both NuBus and PCI PowerMac memory mapping.
User avatar
ClockWise
Site Admin
Posts: 4456
Joined: Mon May 20, 2002 4:37 am
Location: Uiwang

Re: Programming my own Mac emulator

Post by ClockWise »

Hey, keep sharing your updates. Nice to see a long-time forum member creating something really new.
kataetheweirdo
Master Emulator
Posts: 320
Joined: Sun Feb 01, 2009 4:55 pm

Re: Programming my own Mac emulator

Post by kataetheweirdo »

So, on two different Macs so far, the Power Mac G3 Beige and the Power Mac 6100, we've gotten up to the point where it starts playing the boot chime.

That said, we're also considering moving this project from C++11 to Rust. Mainly because Rust is a bit more modern in so many ways (dependency management, code interoperation, Some speed-ups (though this is somewhat subjective) etc.)
User avatar
adespoton
Forum All-Star
Posts: 4473
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com

Re: Programming my own Mac emulator

Post by adespoton »

That's great on getting past the hardware tests and OF initialization!

How hard does the migration from C++11 to Rust look? I've never attempted a re-implementation in Rust, but it looks much more doable than doing a legacy language re-implementation. Are you planning on sticking some legacy code in libraries to import, or just write it all from scratch?
kataetheweirdo
Master Emulator
Posts: 320
Joined: Sun Feb 01, 2009 4:55 pm

Re: Programming my own Mac emulator

Post by kataetheweirdo »

It would be somewhat difficult, but DingusPPC is largely coded like a C program with some C++ bits here and there and encapsulated. We would mostly just stick with C++ for the initial conversion, but use the Rust toolchain to aid us in development.
kataetheweirdo
Master Emulator
Posts: 320
Joined: Sun Feb 01, 2009 4:55 pm

Re: Programming my own Mac emulator

Post by kataetheweirdo »

Right now, we're slowly approaching the point to where we can reach OpenFirmware. However, we also need a lot more work to be done. Here's just some of the things to complete:

VERY HIGH PRIORITY
*Flesh out the debugger to include a disassembler, a memory dumper (in progress), more sophisticated logging, etc.
*Perform CPU tests
*Fix the FPU emulation
*Write up documentation further (preferably in Markdown format) for hardware components (and a lot of it is on a Discord channel that needs to be preserved)
*Implement serial, OpenPIC, video (ATI Rage Pro), and any other hardware components not yet added

HIGH PRIORITY
*Get a proper logging library in the program
*Implement the TLB
*Implement hard drive support
*User input support

MEDIUM PRIORITY
*Acceleration support
*USB device support
*New World ROM support
kataetheweirdo
Master Emulator
Posts: 320
Joined: Sun Feb 01, 2009 4:55 pm

Re: Programming my own Mac emulator

Post by kataetheweirdo »

We improved our debugger significantly, including a disassembler. CPU tests have also been performed, which helped fixed hundreds of small bugs that might not have been noticed otherwise.
User avatar
adespoton
Forum All-Star
Posts: 4473
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com

Re: Programming my own Mac emulator

Post by adespoton »

Nice work! Which PPC instruction set are you emulating at this point? 601?
kataetheweirdo
Master Emulator
Posts: 320
Joined: Sun Feb 01, 2009 4:55 pm

Re: Programming my own Mac emulator

Post by kataetheweirdo »

While it's mostly the G3 instruction set, the 601 does have limited support at the moment (several of the exclusive bit-shifting ops are not yet implemented).

We have included a small dummy ADB emulation, which allows us to complete loading a OpenFirmware bytecode image and it starts going into the cold boot sequence.

Sooner or later, we'll start on the device emulation, but we need to complete documentation and clean up the code further.
kataetheweirdo
Master Emulator
Posts: 320
Joined: Sun Feb 01, 2009 4:55 pm

Re: Programming my own Mac emulator

Post by kataetheweirdo »

We now have audio playback. We've managed to get the boot-up jingle and crash jingle from the Power Mac G3 Beige ROM to play.
User avatar
adespoton
Forum All-Star
Posts: 4473
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com

Re: Programming my own Mac emulator

Post by adespoton »

A thought for you: somewhere (maybe Bend Boldt's old page? Somewhere on the 68kmla forums?) I remember reading that when they were working on getting through booting, they discovered a way to boot off new world ROMs by taking a 68K ROM (3MB) and just byte aligned appending New World in memory after it. So if we can somehow do a clean room implementation of the 68K part (using ARDI's code?) then we can read the New World into memory after it, and it should be enough to boot a New World-capable OS, assuming the hardware side is properly emulated.

Here's a project for part of it: https://github.com/elliotnunn/mac-rom
kataetheweirdo
Master Emulator
Posts: 320
Joined: Sun Feb 01, 2009 4:55 pm

Re: Programming my own Mac emulator

Post by kataetheweirdo »

I do have a 4 MB Gigabit Ethernet ROM, but it doesn't resemble the Old World ROMs much. I'd like to see if anyone can find the page you're mentioning.

While it is possible to make a clean-room implementation, that takes a lot of time and effort to code.
User avatar
adespoton
Forum All-Star
Posts: 4473
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com

Re: Programming my own Mac emulator

Post by adespoton »

Yeah; so far I've just found the annotated Mac Plus ROM, the various romulators, etc. -- but I can't find the ROM replacement project itself anywhere. And of course, the three toolbox replacement projects attempt to skip over the entire ROM issue by doing direct toolbox and API translation instead of just re-implementing the hardware mapping routines and core toolbox functions.
kataetheweirdo
Master Emulator
Posts: 320
Joined: Sun Feb 01, 2009 4:55 pm

Re: Programming my own Mac emulator

Post by kataetheweirdo »

Good news - We fixed some crash bugs, inserted some basic video implementation (though it still won't display anything yet), and have some keyboard work started.

Bad news - To get the keyboard working requires a very timing-specific auto-polling implementation and it's required for emulation to progress any further.
User avatar
Cat_7
Expert User
Posts: 6344
Joined: Fri Feb 13, 2004 8:59 am
Location: Sittard, The Netherlands

Re: Programming my own Mac emulator

Post by Cat_7 »

Perhaps taking a look at the adb work currently being done on Qemu might help?
https://github.com/mcayland/qemu/commits/adb-wip

Best,
Cat_7
kataetheweirdo
Master Emulator
Posts: 320
Joined: Sun Feb 01, 2009 4:55 pm

Re: Programming my own Mac emulator

Post by kataetheweirdo »

https://github.com/dingusdev/dingusppc/tree/debug-68k

Quick branch to help us debug 68k startup code in the Old World ROMs. Capstone is required for this, so you will have to pull that first.
kataetheweirdo
Master Emulator
Posts: 320
Joined: Sun Feb 01, 2009 4:55 pm

Re: Programming my own Mac emulator

Post by kataetheweirdo »

We've managed to debug the 68k ROM up to the point it reaches the BootRetry method.

If anyone can help debug 68k code, here's what we need clarified:

* exception processing (though it mostly has been reversed engineered with the Nanokernel)
* emulator initialization code, especially the part that talks to the Nanokernel
* emulator state control via _MoveFromECR and _MoveToECR traps

This repo will help a lot with digging into the code.
User avatar
adespoton
Forum All-Star
Posts: 4473
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com

Re: Programming my own Mac emulator

Post by adespoton »

Have you connected with Elliot or his team? https://github.com/elliotnunn/powermac-rom

They're active on MacOS9Lives, and are working through similar issues to you right now.
kataetheweirdo
Master Emulator
Posts: 320
Joined: Sun Feb 01, 2009 4:55 pm

Re: Programming my own Mac emulator

Post by kataetheweirdo »

kataetheweirdo
Master Emulator
Posts: 320
Joined: Sun Feb 01, 2009 4:55 pm

Re: Programming my own Mac emulator

Post by kataetheweirdo »

If anyone wants to help with the JIT in DingusPPC, we're currently investigating how to do it. So far, it seems like asmjit would be the best solution. However, we'll also need to carefully manage both PowerPC and 68k code, being aware of the context the OS is currently running in.

Send a direct message to me in Discord (or PM me here) for more info.

Also, we're finishing up the ADB keyboard emulation, but we'd like to know how we should implement the Power key and the NMI. The Control, Option, and Alt keys will also need to be dealt with between OSes, so we'd like to know how to deal with this across different OSes (Windows, Linux, macOS, etc.).
kataetheweirdo
Master Emulator
Posts: 320
Joined: Sun Feb 01, 2009 4:55 pm

Re: Programming my own Mac emulator

Post by kataetheweirdo »

There's a fair amount of updating going on right now. We've managed to reach up to the point the emulator can execute the InitSlots routine. We've also got some debugging stuff inserted and the command line interface is smidge easier to use.
User avatar
ClockWise
Site Admin
Posts: 4456
Joined: Mon May 20, 2002 4:37 am
Location: Uiwang

Re: Programming my own Mac emulator

Post by ClockWise »

You cool if I add a link to the project in the wiki? I won't create a page for it now, but I'll stick it on the "other emulator" page.
kataetheweirdo wrote: Sat Dec 05, 2020 9:06 pm There's a fair amount of updating going on right now. We've managed to reach up to the point the emulator can execute the InitSlots routine. We've also got some debugging stuff inserted and the command line interface is smidge easier to use.
kataetheweirdo
Master Emulator
Posts: 320
Joined: Sun Feb 01, 2009 4:55 pm

Re: Programming my own Mac emulator

Post by kataetheweirdo »

I'd hold off on adding it to the wiki until we can display something, but we're getting there. This year, we've already added some fixes to the instructions and added the mcrf instruction. It tries to initialize the video card, but too much is missing before it can really work. There's also the matter of implementing the interrupt controller.
Post Reply