Page 1 of 4

Programming my own Mac emulator

Posted: Sat Jul 13, 2019 3:16 am
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.

Re: Programming my own Mac emulator

Posted: Sun Jul 21, 2019 4:53 am
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.

Re: Programming my own Mac emulator

Posted: Fri Jul 26, 2019 4:42 am
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.

Re: Programming my own Mac emulator

Posted: Fri Jul 26, 2019 11:49 pm
by ClockWise
Hey, keep sharing your updates. Nice to see a long-time forum member creating something really new.

Re: Programming my own Mac emulator

Posted: Sun Sep 29, 2019 8:25 pm
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.)

Re: Programming my own Mac emulator

Posted: Tue Oct 01, 2019 4:10 pm
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?

Re: Programming my own Mac emulator

Posted: Thu Oct 03, 2019 4:40 am
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.

Re: Programming my own Mac emulator

Posted: Sat Jan 11, 2020 6:02 pm
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

Re: Programming my own Mac emulator

Posted: Sat Feb 29, 2020 4:23 am
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.

Re: Programming my own Mac emulator

Posted: Mon Mar 02, 2020 7:32 pm
by adespoton
Nice work! Which PPC instruction set are you emulating at this point? 601?

Re: Programming my own Mac emulator

Posted: Thu Mar 05, 2020 1:09 am
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.

Re: Programming my own Mac emulator

Posted: Fri Mar 27, 2020 6:18 am
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.

Re: Programming my own Mac emulator

Posted: Fri Mar 27, 2020 3:04 pm
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

Re: Programming my own Mac emulator

Posted: Fri Mar 27, 2020 4:33 pm
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.

Re: Programming my own Mac emulator

Posted: Fri Mar 27, 2020 5:24 pm
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.

Re: Programming my own Mac emulator

Posted: Sun Apr 26, 2020 1:08 am
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.

Re: Programming my own Mac emulator

Posted: Sun Apr 26, 2020 8:39 am
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

Re: Programming my own Mac emulator

Posted: Fri Jul 17, 2020 8:56 pm
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.

Re: Programming my own Mac emulator

Posted: Tue Jul 21, 2020 3:38 am
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.

Re: Programming my own Mac emulator

Posted: Tue Jul 21, 2020 2:20 pm
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.

Re: Programming my own Mac emulator

Posted: Tue Jul 21, 2020 2:53 pm
by kataetheweirdo

Re: Programming my own Mac emulator

Posted: Thu Sep 17, 2020 3:20 am
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.).

Re: Programming my own Mac emulator

Posted: Sat Dec 05, 2020 9:06 pm
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.

Re: Programming my own Mac emulator

Posted: Sun Dec 06, 2020 1:57 am
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.

Re: Programming my own Mac emulator

Posted: Fri Jan 08, 2021 3:06 pm
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.