Compare commits

...
157 Commits
Author SHA1 Message Date
dingusdev af055e0519 Manual tweaks 2025-05-04 17:40:48 -07:00
joevt f2f048d435 hostevents: Fix mouse grab for multiple displays.
Create a mouse grab toggle event to toggle the mouse grab using the current window. After the toggle event is transmitted, transmit a mouse grab changed event so that all windows can update their title.
2025-05-03 06:04:07 -07:00
joevt a62a1dcd09 machinebondi: Grackle machines use separate banks.
For the set of grackle machines, you can change the machine argument without having to change the ram bank sizes arguments.
For example, all grackle machines can specify 1 GiB using two 512 MiB ram banks.
2025-05-01 06:53:04 -07:00
joevt 74da4e148d debugger: Ensure cout fill changes back to right. 2025-04-29 06:31:15 -07:00
joevt c0cd18323e profiler: Ensure cout fill changes back to right. 2025-04-29 06:30:19 -07:00
joevt b848ea2300 ofnvram: Explicitly set cout fill direction. 2025-04-28 19:40:03 -07:00
joevt f9f77f78a8 ofnvram: Set cout fill direction back to right. 2025-04-28 19:39:55 -07:00
joevt f7b88cf5ee machinefactory: Set cout fill to right.
Always set the fill direction explicitly in case someone set it to left elsewhere.
2025-04-28 07:05:32 -07:00
joevt 72dbafdb3f debugger: Format 68K register dump.
Fix alignment and use 8 hex digits for each register.
2025-04-28 07:00:57 -07:00
joevt f55d5c9002 debugger: Use FILENO defines. 2025-04-28 15:05:40 +02:00
dingusdev 65d414bd4e Fixing compile issues 2025-04-28 15:05:40 +02:00
joevt fa5e8b0bf8 amic: Return random value for SCC DMA Rcv.
This allows Mac OS 8.5 and Mac OS 8.5.1 to boot from SCSI of Power Mac 6100.
2025-04-28 15:05:40 +02:00
joevt b05dec8778 viacuda: Add some memory address notes.
These are registers used during boot of Mac OS 8.5 from SCSI on Power Mac 6100.
2025-04-27 09:27:02 -07:00
joevt 24a18f7769 amic: Define local variable in minimum scope. 2025-04-27 07:33:30 -07:00
joevt a74ad4b1d1 amic: Add some register notes.
These are registers used during boot of Mac OS 8.5 from SCSI.
2025-04-27 07:32:33 -07:00
joevt 6c430b7d83 poweropcodes: Use ROTR_32 where possible. 2025-04-24 19:16:43 -07:00
dingusdev 2ce4e13170 ROTL_32 header fixes 2025-04-24 06:36:11 -07:00
joevt 746f461c5b ppcopcodes: Use ROTL_32 where possible. 2025-04-24 06:34:52 -07:00
joevt 00be8ce606 display: Fix update_mouse_grab.
Need to ungrab the mouse to move it.
2025-04-24 06:34:18 -07:00
joevt a1f15228fd display: Fix Visual Studio compiler warnings. 2025-04-24 06:34:04 -07:00
joevt 16762ab9e3 bitops: Handle rotate count 0. 2025-04-24 06:33:54 -07:00
joevt 28c497e455 bitops: Spelling. 2025-04-24 06:33:31 -07:00
joevt 5b3043c372 ppcfpopcodes: Remove redundant expression. 2025-04-24 06:33:22 -07:00
joevt 0019681be4 Properly merge "display: Remove resizing flag." 2025-04-23 21:12:03 -07:00
dingusdev c1ed416b58 Revert "display: Remove resizing flag."
This reverts commit c781ba8fab.
2025-04-23 21:08:45 -07:00
joevt 72ef266d07 display: Update grabbed mouse when resizing.
If the window's size is reduced such that the grabbed mouse is no longer inside the window, then a mouse click will go to another app. Therefore, check the mouse position and update if necessary every time the window changes size.
2025-04-23 06:56:25 -07:00
joevt c781ba8fab display: Remove resizing flag.
It doesn't do anything useful yet and setting the resizing flag to true stops updates if the window doesn't actually change size.
2025-04-23 06:50:24 -07:00
joevt c6013f076a ppcmmu: Fix DMA for adjacent cross region ranges.
If a DMA range extends beyond the end of a region into a second region of the same type (either RAM or ROM), and the regions are adjacent in both the guest and host address spaces, then allow the DMA to proceed.
2025-04-23 06:32:28 -07:00
joevt 9c6a7de45f ppcopcodes: Remove unnecessary type casts. 2025-04-23 06:15:38 -07:00
joevt 47c66666bb display: Add zoom and fullscreen no letterbox.
Added a third full screen mode which removes letterbox or pillarbox black bars.
Added Control-- and control-+ to decrease or increase the scale by a factor of 2^(1/8). This means the scale doubles or halves after pressing the same key 8 times.

drawable_w and drawable_h are floating point so that scaling is reversible (i.e. scaling from 100% to 800% and back to 100% gives 100% instead of 99 or 101%).
default_scale_x

Handle switching host resolution between Retina (HiDPI) and Low resolution modes. This involves updating the window scale factor.

Add window scale factor to window title.
2025-04-22 06:36:04 -07:00
dingusdevandlefp 534d092bd5 Quick fix for Alacritty support
Co-Authored-By: lefp <[email protected]>
2025-04-21 18:28:03 -07:00
dingusdevandBen Boeckel 4d0904667c loguru: use iscntrl to test for control characters
Snatching a pull request from Loguru

Co-Authored-By: Ben Boeckel <[email protected]>
2025-04-21 18:23:50 -07:00
joevt e82d9d1522 Add Full Screen modes.
A display begins in Windowed mode.
1) Press Control-F once to use full screen mode with integer scaling. If this mode is the same size as full screen mode then it is skipped.
2) Press Control-F again to use full screen mode. Smooth Scaling should be used for this mode if the scaling is not integer. Look at the Mac OS 7/8/9 window stripes to see the problem.
3) Press Control-F a third time to get back to windowed mode.

Fixed a bug where Control-S (Toggle Smooth Scaling mode) did not immediately update the display.

These keys only affect the current display.
2025-04-19 05:38:37 -07:00
joevt e64cf73543 manual: Minor edits. 2025-04-19 05:35:37 -07:00
dingusdev 88b5b2ec66 Prep for Alpha 1.0.3 2025-04-18 21:22:19 -07:00
joevt 1340fbedb8 hostevends_sdl: Check all modifier keys.
When checking if certain modifier keys are being pressed, also make sure that all other modifier keys are not being pressed.
2025-04-18 18:51:47 -07:00
joevt 36c7c807a4 display: Add update_window_title and window event.
update_window_title can be used to update statistics about the display (such as display resolution) or about DingusPPC in general (such as "mouse grabbed" status).

A DPPC_WINDOWEVENT_MOUSE_GRAB_CHANGED window event is added so that Display::handle_events can update the "mouse grabbed" indicator in each display window. The event handler doesn't check the window ID because the status should be reflected in all windows.

The SDL_WINDOWEVENT_SIZE_CHANGED event causes the window to update the display resolution indicator.

In the future, we might add indicators for HD and CD and floppy disk activity, etc. They will be handled by a window event handler or a general DPPC event handler.
2025-04-18 07:20:49 -07:00
Rairii 61a8402f84 hostevents_sdl: Ralt+delete to ctrl+alt+del.
"Right Option + Forward Delete" is translated to "Control + Right Option + Backspace".
2025-04-18 07:20:46 -07:00
Maxim Poliakovski d315624d54 ppcopcodes: refactor rfi to reduce code duplication. 2025-04-16 00:58:27 +02:00
joevt ec6fa9360c ppcopcodes: Cleanup ppc_rfi.
Reduce the number of operations by 1
and make more clear what is happening.
2025-04-16 00:51:13 +02:00
joevt 0fe6ffeb6f ppcemu: reformat and extend MSR enum. 2025-04-15 18:52:52 +02:00
joevt 2f8e8bf68b videoctrl: Spelling. 2025-04-14 06:40:57 -07:00
joevt a5e2adefa9 atimach64gx: Add RGB 514 read and CLUT_ADDR_RD. 2025-04-14 06:27:46 -07:00
joevt 16542a09f5 atimach64gx: Add rgb514_write_reg logging. 2025-04-14 06:22:50 -07:00
joevt fa865a79fc memctrlbase: Log mirror range.
Because it may differ from the range of the region it points to.
2025-04-14 06:06:42 -07:00
joevt fa7fb5bb1f hammerhead: Define some bits.
From xnu-344/osfmk/ppc/POWERMAC/mp/MPPlugIn.h
2025-04-12 10:20:54 -07:00
joevt 0899d84019 hammerhead: Cleanup.
Replace all occurrences of offset >> 1 with bank.
2025-04-12 08:38:38 -07:00
joevt 3e88c161c1 platinum: Fix PAL/NTSC interlaced display. 2025-04-12 08:38:36 -07:00
joevt 2253e6c595 platinum: Remove spaces. 2025-04-12 08:38:35 -07:00
joevt 86a09a9d3c platinum: Add RAM. 2025-04-12 08:38:33 -07:00
joevt 71990129f3 memctrlbase: Remove region by entry. 2025-04-12 08:38:32 -07:00
Maxim Poliakovski ab8abf39cc amic: remove deprecated SCSI DMA code. 2025-04-11 19:24:56 +02:00
Maxim Poliakovski 8c84b78804 sc53c94: fix bus reset interrupt generation. 2025-04-11 19:24:56 +02:00
Maxim Poliakovski 4312450b70 sc53c94: preliminary support for CMD_XFER_PAD_BYTES.
MkLinux uses this command during synchronous transfer
negotiation.
2025-04-11 19:24:56 +02:00
Maxim Poliakovski a75d806108 Better support for SCSI messages. 2025-04-11 19:19:38 +02:00
Maxim Poliakovski 2a830154f9 sc53c94: implement CMD_SELECT_WITH_ATN_AND_STOP command. 2025-04-11 19:07:35 +02:00
Maxim Poliakovski 89d5196e8b sc53c94: implement CMD_RESET_ATN command. 2025-04-11 19:07:35 +02:00
Maxim Poliakovski 842d0f7f70 sc53c94: improve CMD_MSG_ACCEPTED. 2025-04-11 19:04:47 +02:00
Maxim Poliakovski 23ea02b47c sc53c94: replace some magic numbers with constants. 2025-04-11 19:04:47 +02:00
Maxim Poliakovski 5bd1071d10 scsihd: add support for START_STOP_UNIT.
MkLinux won't boot if this command fails.
2025-04-11 19:04:47 +02:00
Rairii be59ed8304 atapicdrom: Postpone data out phase. 2025-04-09 22:01:15 -07:00
Rairii e4dedb8c09 atapicdrom: Error if read while xfer in progress. 2025-04-09 22:01:06 -07:00
Rairii 17f2562d13 atapicdrom: Short circuit zero length reads. 2025-04-09 21:56:48 -07:00
Rairii 6adce6b120 atapibasedevice: Extra steps when reading STATUS. 2025-04-09 21:56:46 -07:00
Rairii aec5aba379 blockstoragedevice: Use 64-bit math. 2025-04-09 21:56:45 -07:00
Rairii f40ce18bc5 atabasedevice: Postpone data ready signal. 2025-04-09 21:56:44 -07:00
Rairii e4f0588b56 atabasedevice: Postpone write complete interrupt. 2025-04-09 21:56:43 -07:00
Rairii 7ab54276ad atabasedevice: Postpone read complete interrupt. 2025-04-09 21:56:42 -07:00
Rairii 630755f9e5 atabasedevice: Include timermanager. 2025-04-09 21:56:39 -07:00
Maxim Poliakovski 0efab12699 Rename ScsiMsg to avoid ambiguity. 2025-04-09 13:28:15 +02:00
joevt b280da81bc ppc: Timing calculation changes.
Note: all timings are relative to virtual time which is 16 ns per instruction. 8 ns per instruction is too fast for the PDM 'mach' gestalt calculation in firmware.

- For MPC601, bit 7 of RTC and DEC changes at 7.8336 MHz so bit 0 would change at 1.0027008 GHz. Therefore multiply time base frequency by 128. For MPC601, DEC now changes at 1.0027008 GHz instead of 7.8336 MHz.
- Add tbr_freq_shift for cases where time base frequency exceeds 1GHz.
- Change calc_rtcl_value to use time base frequency. For MPC601, RTC now changes at 1.0027008 GHz instead 1GHz.
- For MPC601, the 7 least significant bits of DEC are not implemented so make them not getable or setable.
2025-04-08 19:46:48 -07:00
joevt 6363eef32f ppcexec: Make opcode macros depend on OPr. 2025-04-08 19:46:20 -07:00
joevt 2b4962d1ba sc53c94: Add "this" for class members. 2025-04-05 19:06:41 -07:00
joevt d66c2a39a3 athens: Change pixel clock default.
It should not be 0 MHz because that causes the virtual display to freeze.
Default to 50 MHz so that 800x600 72Hz can work for "control" video output.
2025-04-05 18:59:59 -07:00
Maxim Poliakovski fe304d9f46 sc53c94: support Synchronous Transfer Period register. 2025-04-05 13:11:06 +02:00
joevt 081e0f0576 machinegossamer: Define default GPU property.
Continuation of commit "Define default GPU PCI device property value."
2025-04-04 20:52:29 -07:00
joevt a628d8aa5d machinegazelle: Remove cdr_config property.
cdr_config is for IDE buses. Power Mac 6500 has SCSI CD-ROM.

Continuation of commit "Define default GPU PCI device property value."
2025-04-04 20:52:25 -07:00
joevt b2bff25cc2 machinebondi: Remove AtiMach64Gx.
Continuation of commit "Define default GPU PCI device property value."
2025-04-04 20:52:22 -07:00
joevt 3940080f78 main: Support empty properties.
For example, to remove the GPU of a Gossamer machine, use --pci_GPU=

Continuation of commit "Define default GPU PCI device property value."
2025-04-04 20:52:19 -07:00
joevt 28c50a2018 hostevents: Spaces. 2025-04-04 20:52:05 -07:00
Maxim Poliakovski 3e3eee7ae9 pdmonboard: check framebuffer location on video refresh.
That fixes video for MkLinux.
2025-04-04 18:09:11 +02:00
joevt 41aa8b73e9 cmake: Add USB and FireWire directories. 2025-04-04 06:58:50 -07:00
dingusdev 556d00116f Fixed compile 2025-04-04 06:52:16 -07:00
joevt f4d40ae26b Define default GPU PCI device property value. 2025-04-04 06:49:21 -07:00
Rairii ca55defc55 atabasedevice: Don't attempt command while busy. 2025-04-04 06:40:33 -07:00
joevt 43f5b56033 machineyosemite: Add 512 MB DIMM option.
The max RAM is still 1 GB.
2025-04-04 06:33:22 -07:00
joevt 8484e52407 machinegossamer: Increase max RAM to 1 GB.
Two 512 MB DIMMs gives the max 1 GB of RAM.
2025-04-04 06:33:12 -07:00
joevt 1565d21176 mpc106: Handle overlapping banks. 2025-04-04 06:27:32 -07:00
joevt 986fc22fd4 mpc106: Fix RAM allocation again.
For greater than 4 banks.
2025-04-04 06:27:13 -07:00
joevt 1046baf11d spdram: Add 8 MB DIMMs. 2025-04-03 18:16:44 -07:00
Rairii c4906d1f15 spdram: Add 16 MB DIMMs. 2025-04-03 18:16:38 -07:00
joevt a5dc3bceb9 atirage: Allow up to 8MB of VRAM.
8MB of VRAM is required for 32-bit color at 1600x1200 or 1920x1080. See imacg3 with AtiRagePro.
2025-04-03 07:56:12 -07:00
joevt 3bab9b6f52 endianswap: Convert tabs to spaces. 2025-04-03 07:42:30 -07:00
joevt 25beb13b1b sc53c94: Remove extra space. 2025-04-03 07:42:08 -07:00
joevt 99c06e8690 machinebondi: Increase max RAM to 1 GB. 2025-04-03 07:40:30 -07:00
joevt c483a9a615 spdram: Add 512 MB DIMMs. 2025-04-03 07:40:20 -07:00
joevt 4b25da926b sixty6: Default pixel depth should be 8.
At least in one case I tested.
2025-04-02 07:31:47 -07:00
joevt 06a9e338a9 machinegazelle: Add a default GPU. 2025-04-02 07:12:27 -07:00
joevt 26db2caadd Move ControlVideo to Chaos. 2025-04-02 07:11:26 -07:00
Maxim Poliakovski ff6d75f232 sc53c94: remove unused code. 2025-04-01 16:04:18 +02:00
Maxim Poliakovski f6f11e81e9 Switch AMIC SCSI DMA to the new DMA API. 2025-04-01 04:02:51 +02:00
Maxim Poliakovski c742beb623 sc53c94: return actual number of bytes transferred
in xfer_to and xfer_from methods.
2025-04-01 04:02:51 +02:00
Maxim Poliakovski ba030abb3b scsihd: don't return error for DEFAULT VALUES in MODE_SENSE_6.
Page control 2 (DEFAULT VALUES) in MODE_SENSE_6 may not fail.
2025-04-01 04:02:51 +02:00
Maxim Poliakovski df5c1758d5 sc53c94: don't generate Bus Service int when asserting DREQ.
Generating Bus Service interrupt while asserting DREQ breaks
the Old SCSI API and the applications that depend on it.
2025-04-01 04:02:14 +02:00
Maxim Poliakovski b5edd8347e dbdma.h: add missing 'override'. 2025-04-01 04:02:14 +02:00
Maxim Poliakovski ed433c0476 scsibusctrl: add missing 'override'. 2025-04-01 04:02:14 +02:00
Maxim Poliakovski fb03c214ae sc53c94: add missing 'override'. 2025-04-01 04:02:14 +02:00
Maxim Poliakovski 503c6ea662 sc53c94: fix DMA transfers for BeOS.
Mac OS SCSI Manager starts the DMA engine after issuing
a data transfer command to the controller. The device will
assert REQ, then sit and wait for the DMA engine to transfer
data.
Be OS driver does that in the reverse order: the DMA engine
is initialized first, then the controller is instructed to
transfer data.
This commit adds support for both ways.
2025-04-01 04:01:26 +02:00
Maxim Poliakovski 2d61e4c604 dbdma: implement new DmaChannel methods. 2025-04-01 04:01:26 +02:00
Maxim Poliakovski 03bb03fdd5 dmacore: extend DmaChannel API. 2025-04-01 04:01:26 +02:00
Maxim Poliakovski c10183b58f sc53c94: fix sequence step reporting for BeOS. 2025-04-01 04:00:44 +02:00
Maxim Poliakovski be1b567b84 sc53c94: fix handling of multistep commands. 2025-04-01 04:00:44 +02:00
Maxim Poliakovski 237f983493 sc53c94: correct status register emulation. 2025-04-01 04:00:44 +02:00
Maxim Poliakovski 2a3e46eab4 memctrlbase: overload add_ram_region()
to accept externally allocated memory.
2025-04-01 03:05:46 +02:00
joevt d4d19e880c Update Inquiry methods.
ScsiCdrom has an inquiry method that overloads a method in CdromDrive. Make it so that it's a valid override (not overloaded).
For CdromDrive, allow inquiry method to work with lengths <> 36 like the SCSI versions.
For ScsiHarDisk, the inquiry method is not on override or an overload, but make it like the ScsiCdrom version anyway.
2025-03-30 09:40:05 -07:00
joevt 1166fda3e0 heathrow: Connect mesh. 2025-03-30 07:58:34 -07:00
joevt 8b1d673e10 More documentation fixes. 2025-03-30 07:41:15 -07:00
dingusdev 4ac5fd4cb0 Minute documentation fixes 2025-03-29 10:47:28 -07:00
joevt 6da691fb02 atimach64gx: Change logging. 2025-03-29 10:35:59 -07:00
joevt 8f64d35210 atimach64gx: Fix logging. 2025-03-29 10:35:51 -07:00
joevt 61d73a5b79 atimach64gx: Add register reading methods.
In case they are needed in the future.
2025-03-29 10:30:59 -07:00
joevt 794a345e53 atimach64gx: Add logging for registers.
WRITE_VALUE_AND_LOG logs the value that was written to the register and the result that can be read from the register. Use this if you need to write the register before acting upon the changes to the register and use return instead of break to bypass the default path which also calls WRITE_VALUE_AND_LOG after the switch statement.
2025-03-29 10:25:55 -07:00
joevt 1c54cdd368 atimach64gx: Add logging to crtc_update. 2025-03-29 10:25:45 -07:00
joevt 026d53f275 atimach64gx: Log unmapped aperture region accesses. 2025-03-29 10:14:51 -07:00
joevt ca20de9462 atimach64gx: Log rgb514 indirect register writes. 2025-03-29 10:14:40 -07:00
dingusdev 7893d0add7 More BigMac regs + descriptions 2025-03-29 08:58:19 -07:00
joevt 7f34504259 atimach64gx: Log I/O register accesses. 2025-03-29 07:07:46 -07:00
dingusdev 48fd95e284 Add additional BMAC registers 2025-03-28 21:38:33 -07:00
dingusdevandRairii 15baf9a2a0 Add Bondi (iMac G3)
Co-Authored-By: Rairii <[email protected]>
2025-03-28 18:31:00 -07:00
joevt a0edc825fb macio: Add comment for MIO_OH_FC_IN_USE_LED flag. 2025-03-25 21:44:35 -07:00
joevt 20e7dfb0e1 macio: Log unsupported DMA channels once.
For debugging. No need to spam the log.
2025-03-25 21:39:49 -07:00
joevt 83066bbf5f memctrlbase: Return entry instead of bool. 2025-03-24 07:29:31 -07:00
joevt 637c20e3cf grandcentral: Handle bit-flipping of MAC address.
If the ENET ROM begins with 0x10, then the bits of each byte are flipped 7..0 -> 0..7 which means the MAC address will begin with 0x08.
A MAC address beginning with 0x08 can be bit-flipped or not bit-flipped.
A MAC address cannot begin with 0x10.
I have a `dump-device-tree` output for a Power Mac 9500 with MAC address beginning with 08-00-07 (OUI for "Apple, Inc."). I don't know if it's using the bit-flipped ROM (starting with 10) or not bit-flipped ROM (starting with 08).
Most of the other `dump-device-tree` outputs I've seen have a MAC address beginning with an OUI for "Apple, Inc." that begins with 00.
2025-03-24 06:39:55 -07:00
joevt ba9bbb32c3 Catch all errors for debug read/write methods. 2025-03-23 16:14:31 -07:00
Rairii 60c95231ee atimach64gx: Don't allow pitch to be zero. 2025-03-22 21:00:18 -07:00
dingusdev 130beabf2a Re-insert code for tlbia
BeOS uses this as part of its boot handler.
2025-03-21 18:57:17 -07:00
dingusdev a7170f4956 Removing code for tlbia
Seems to be causing a regression in Mac OS X 10.0
2025-03-21 18:42:56 -07:00
dingusdev 10f087be65 Maintenance on ATI Rage code 2025-03-21 07:52:04 -07:00
joevt 392f6cdcd3 mpc106: Document flash ROM related registers. 2025-03-21 07:30:18 -07:00
joevt e43bb02d9a debugger: Remove unused variable in patch_mem. 2025-03-20 19:31:10 -07:00
dingusdev 341d5470a2 Update cubeb 2025-03-20 19:30:05 -07:00
dingusdev 2b0c932e48 Continued fix-ups, for GCC 2025-03-18 19:00:15 -07:00
dingusdevandAndrew Randrianasulu 35095870b2 Fix some warnings for Loguru
Co-Authored-By: Andrew Randrianasulu <[email protected]>
2025-03-18 18:50:35 -07:00
dingusdev a178d12a80 Attempt to fix MSYS2 compile 2025-03-16 14:31:23 -07:00
dingusdev 43361815d2 Update CREDITS.md 2025-03-16 14:26:40 -07:00
dingusdev ddb3657d89 Merge pull request #140 from mrpapersonic/master
endianswap: use byteswap.h when available, and use inline functions for generic impl
2025-03-16 10:07:38 -07:00
Paper 8ce9abcf22 endianswap: use byteswap.h when available, and use inline functions for generic impl 2025-03-16 12:47:59 -04:00
dingusdev aee50331e9 Merge pull request #139 from mrpapersonic/master
endianswap: fix 64-bit byteswap macro on weird compilers
2025-03-16 07:33:36 -07:00
Paper f784cedc0b endianswap: fix 64-bit byteswap macro on weird compilers 2025-03-15 23:07:29 -04:00
joevt d300a31fa7 swim3: Ensure 32-bit multiply result. 2025-03-15 16:26:31 -07:00
dingusdev 9874aa1dfc Small bit of clean-up for PDM Video 2025-03-14 14:39:54 -07:00
dingusdevandjoevt 08f67c010c Add get_type_str + get_entry+str
Co-Authored-By: joevt <[email protected]>
2025-03-14 10:43:37 -07:00
joevt c3005cede3 debugger: Catch memory errors while disassembling. 2025-03-14 10:40:49 -07:00
joevt cf0d78fe98 debugger: add regions command.
To dump the list of memory regions.
2025-03-14 10:31:57 -07:00
Maxim Poliakovski 8aede43f91 scsidevice: remove dead code. 2025-03-14 17:52:48 +01:00
Maxim Poliakovski a7386a648e macio.h: remove unused class members. 2025-03-14 17:52:48 +01:00
Maxim Poliakovski 69c4d6489d debugger: implement setmem command. 2025-03-14 17:52:48 +01:00
88 changed files with 2472 additions and 751 deletions

No files matched your search

+11
View File
@@ -23,11 +23,22 @@
- kth5
- dyharlan
- roytam1
- mrpapersonic
- Randrianasulu
- lefp
- mathstuf
## Testing
- LagLifeYT
## 3rd Party Libraries
- [Capstone](https://github.com/capstone-engine/capstone)
- [CLI11](https://github.com/CLIUtils/CLI11)
- [Loguru](https://github.com/emilk/loguru)
- [SDL 2](https://github.com/libsdl-org/SDL)
## Thanks
- 68kmla
+8 -4
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -44,16 +44,20 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
// cyclic rotation idioms that modern compilers will
// recognize and generate very compact code for
// evolving specific machine instructions
// involving specific machine instructions
inline unsigned ROTL_32(unsigned x, unsigned n) {
n &= 0x1F;
return (x << n) | (x >> (32 - n));
if (n)
return (x << n) | (x >> (32 - n));
return x;
}
inline unsigned ROTR_32(unsigned x, unsigned n) {
n &= 0x1F;
return (x >> n) | (x << (32 - n));
if (n)
return (x >> n) | (x << (32 - n));
return x;
}
#endif
+8 -3
View File
@@ -36,9 +36,14 @@ public:
};
enum : uint16_t {
// Standard SDL window event types are uint8_t's, we add our own custom
// events after that.
WINDOW_SCALE_QUALITY_TOGGLE = 1 << 8,
// Standard SDL window event types are uint8_t's.
// We add our own custom events after that.
DPPC_WINDOWEVENT_WINDOW_SCALE_QUALITY_TOGGLE = 1 << 8,
DPPC_WINDOWEVENT_MOUSE_GRAB_TOGGLE,
DPPC_WINDOWEVENT_MOUSE_GRAB_CHANGED,
DPPC_WINDOWEVENT_WINDOW_FULL_SCREEN_TOGGLE,
DPPC_WINDOWEVENT_WINDOW_BIGGER,
DPPC_WINDOWEVENT_WINDOW_SMALLER,
};
enum : uint32_t {
+62 -29
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -29,7 +29,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
EventManager* EventManager::event_manager;
static int get_sdl_event_key_code(const SDL_KeyboardEvent& event, uint32_t kbd_locale);
static void toggle_mouse_grab(const SDL_KeyboardEvent &event);
constexpr int KMOD_ALL = KMOD_LSHIFT | KMOD_RSHIFT | KMOD_LCTRL | KMOD_RCTRL | KMOD_LALT | KMOD_RALT | KMOD_LGUI | KMOD_RGUI;
void EventManager::poll_events(uint32_t kbd_locale) {
SDL_Event event;
@@ -55,22 +56,76 @@ void EventManager::poll_events(uint32_t kbd_locale) {
case SDL_KEYUP: {
// Internal shortcuts, intentionally not sent to the host.
// Control-G: mouse grab
if (event.key.keysym.sym == SDLK_g && SDL_GetModState() & KMOD_LCTRL) {
if (event.key.keysym.sym == SDLK_g && (SDL_GetModState() & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
toggle_mouse_grab(event.key);
WindowEvent we;
we.sub_type = DPPC_WINDOWEVENT_MOUSE_GRAB_TOGGLE;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
we.sub_type = DPPC_WINDOWEVENT_MOUSE_GRAB_CHANGED;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
}
return;
}
// Control-S: scale quality
if (event.key.keysym.sym == SDLK_s && SDL_GetModState() & KMOD_LCTRL) {
if (event.key.keysym.sym == SDLK_s && (SDL_GetModState() & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
WindowEvent we{};
we.sub_type = WINDOW_SCALE_QUALITY_TOGGLE;
we.sub_type = DPPC_WINDOWEVENT_WINDOW_SCALE_QUALITY_TOGGLE;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
}
return;
}
// Control-F: fullscreen
if (event.key.keysym.sym == SDLK_f && (SDL_GetModState() & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
WindowEvent we{};
we.sub_type = DPPC_WINDOWEVENT_WINDOW_FULL_SCREEN_TOGGLE;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
}
return;
}
// Control-+: bigger
if (event.key.keysym.sym == SDLK_EQUALS && (SDL_GetModState() & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
WindowEvent we{};
we.sub_type = DPPC_WINDOWEVENT_WINDOW_BIGGER;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
}
return;
}
// Control--: smaller
if (event.key.keysym.sym == SDLK_MINUS && (SDL_GetModState() & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
WindowEvent we{};
we.sub_type = DPPC_WINDOWEVENT_WINDOW_SMALLER;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
}
return;
}
// Ralt+delete => ctrl+alt+del
if (event.key.keysym.sym == SDLK_DELETE && ((SDL_GetModState() & KMOD_ALL) == KMOD_RALT) != 0) {
KeyboardEvent ke{};
ke.key = AdbKey_Control;
if (event.type == SDL_KEYDOWN) {
ke.flags = KEYBOARD_EVENT_DOWN;
key_downs++;
} else {
ke.flags = KEYBOARD_EVENT_UP;
key_ups++;
}
this->_keyboard_signal.emit(ke);
ke.key = AdbKey_Delete;
this->_keyboard_signal.emit(ke);
return;
}
int key_code = get_sdl_event_key_code(event.key, kbd_locale);
if (key_code != -1) {
KeyboardEvent ke{};
@@ -334,7 +389,7 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_l
return AdbKey_JIS_Yen;
case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL1):
return AdbKey_JIS_Underscore;
case 0XBC:
case 0XBC:
return AdbKey_JIS_KP_Comma;
case 0X89:
return AdbKey_JIS_Eisu;
@@ -373,25 +428,3 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_l
}
return -1;
}
static void toggle_mouse_grab(const SDL_KeyboardEvent &event) {
SDL_Window *window = SDL_GetWindowFromID(event.windowID);
if (SDL_GetRelativeMouseMode()) {
SDL_SetRelativeMouseMode(SDL_FALSE);
SDL_SetWindowTitle(window, "DingusPPC Display");
} else {
// If the mouse is initially outside the window, move it to the middle,
// so that clicks are handled by the window (instead making it lose
// focus, at least with macOS hosts).
int mouse_x, mouse_y, window_x, window_y, window_width, window_height;
SDL_GetGlobalMouseState(&mouse_x, &mouse_y);
SDL_GetWindowPosition(window, &window_x, &window_y);
SDL_GetWindowSize(window, &window_width, &window_height);
if (mouse_x < window_x || mouse_x >= window_x + window_width ||
mouse_y < window_y || mouse_y >= window_y + window_height) {
SDL_WarpMouseInWindow(window, window_width / 2, window_height / 2);
}
SDL_SetRelativeMouseMode(SDL_TRUE);
SDL_SetWindowTitle(window, "DingusPPC Display (Mouse Grabbed)");
}
}
+18 -18
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -22,6 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
// The Power-specific opcodes for the processor - ppcopcodes.cpp
// Any shared opcodes are in ppcopcodes.cpp
#include <core/bitops.h>
#include "ppcemu.h"
#include "ppcmacros.h"
#include "ppcmmu.h"
@@ -341,9 +342,8 @@ void dppc_interpreter::power_rlmi(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_mb = (opcode >> 6) & 0x1F;
unsigned rot_me = (opcode >> 1) & 0x1F;
unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t r = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
uint32_t r = ROTL_32(ppc_result_d, ppc_result_b);
uint32_t mask = power_rot_mask(rot_mb, rot_me);
ppc_result_a = ((r & mask) | (ppc_result_a & ~mask));
@@ -380,7 +380,7 @@ void dppc_interpreter::power_sle(uint32_t opcode) {
unsigned rot_sh = ppc_result_b & 0x1F;
ppc_result_a = ppc_result_d << rot_sh;
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
ppc_state.spr[SPR::MQ] = ROTL_32(ppc_result_d, rot_sh);
ppc_store_iresult_reg(reg_a, ppc_result_a);
@@ -397,7 +397,7 @@ template <field_rc rec>
void dppc_interpreter::power_sleq(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t r = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
uint32_t r = ROTL_32(ppc_result_d, rot_sh);
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
@@ -417,7 +417,7 @@ void dppc_interpreter::power_sliq(uint32_t opcode) {
ppc_grab_regssash(opcode);
ppc_result_a = ppc_result_d << rot_sh;
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
ppc_state.spr[SPR::MQ] = ROTL_32(ppc_result_d, rot_sh);
if (rec)
ppc_changecrf0(ppc_result_a);
@@ -431,7 +431,7 @@ template void dppc_interpreter::power_sliq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_slliq(uint32_t opcode) {
ppc_grab_regssash(opcode);
uint32_t r = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
uint32_t r = ROTL_32(ppc_result_d, rot_sh);
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
@@ -480,7 +480,7 @@ void dppc_interpreter::power_slq(uint32_t opcode) {
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
ppc_state.spr[SPR::MQ] = ROTL_32(ppc_result_d, rot_sh);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
@@ -492,7 +492,7 @@ void dppc_interpreter::power_sraiq(uint32_t opcode) {
ppc_grab_regssash(opcode);
uint32_t mask = (1U << rot_sh) - 1;
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
if ((int32_t(ppc_result_d) < 0) && (ppc_result_d & mask)) {
ppc_state.spr[SPR::XER] |= XER::CA;
@@ -515,7 +515,7 @@ void dppc_interpreter::power_sraq(uint32_t opcode) {
unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t mask = (ppc_result_b & 0x20) ? -1 : (1U << rot_sh) - 1;
ppc_result_a = (int32_t)ppc_result_d >> ((ppc_result_b & 0x20) ? 31 : rot_sh);
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
ppc_state.spr[SPR::MQ] = ROTL_32(ppc_result_d, rot_sh);
if ((int32_t(ppc_result_d) < 0) && (ppc_result_d & mask)) {
ppc_state.spr[SPR::XER] |= XER::CA;
@@ -523,7 +523,7 @@ void dppc_interpreter::power_sraq(uint32_t opcode) {
ppc_state.spr[SPR::XER] &= ~XER::CA;
}
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
if (rec)
ppc_changecrf0(ppc_result_a);
@@ -541,7 +541,7 @@ void dppc_interpreter::power_sre(uint32_t opcode) {
unsigned rot_sh = ppc_result_b & 0x1F;
ppc_result_a = ppc_result_d >> rot_sh;
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
if (rec)
ppc_changecrf0(ppc_result_a);
@@ -557,7 +557,7 @@ void dppc_interpreter::power_srea(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
uint32_t r = (rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d);
uint32_t r = ROTR_32(ppc_result_d, rot_sh);
uint32_t mask = -1U >> rot_sh;
if ((int32_t(ppc_result_d) < 0) && (r & ~mask)) {
@@ -583,7 +583,7 @@ void dppc_interpreter::power_sreq(uint32_t opcode) {
uint32_t mask = -1U >> rot_sh;
ppc_result_a = (ppc_result_d >> rot_sh) | (ppc_state.spr[SPR::MQ] & ~mask);
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
if (rec)
ppc_changecrf0(ppc_result_a);
@@ -598,7 +598,7 @@ template <field_rc rec>
void dppc_interpreter::power_sriq(uint32_t opcode) {
ppc_grab_regssash(opcode);
ppc_result_a = ppc_result_d >> rot_sh;
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
if (rec)
ppc_changecrf0(ppc_result_a);
@@ -612,7 +612,7 @@ template void dppc_interpreter::power_sriq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_srliq(uint32_t opcode) {
ppc_grab_regssash(opcode);
uint32_t r = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
uint32_t r = ROTR_32(ppc_result_d, rot_sh);
unsigned mask = power_rot_mask(rot_sh, 31);
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
@@ -631,7 +631,7 @@ template <field_rc rec>
void dppc_interpreter::power_srlq(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t r = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
uint32_t r = ROTR_32(ppc_result_d, rot_sh);
unsigned mask = power_rot_mask(rot_sh, 31);
if (ppc_result_b & 0x20) {
@@ -660,7 +660,7 @@ void dppc_interpreter::power_srq(uint32_t opcode) {
ppc_result_a = ppc_result_d >> rot_sh;
}
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
if (rec)
ppc_changecrf0(ppc_result_a);
+48 -15
View File
@@ -177,6 +177,7 @@ extern uint64_t rtc_timestamp;
extern uint64_t tbr_wr_value;
extern uint32_t dec_wr_value;
extern uint32_t tbr_freq_ghz;
extern uint32_t tbr_freq_shift;
extern uint64_t tbr_period_ns;
extern uint32_t rtc_lo, rtc_hi;
@@ -244,22 +245,54 @@ enum FPSCR : uint32_t {
FX = 1UL << 31
};
/** Bit definitions for the Machine State Register (MSR). */
enum MSR : int {
LE = 0x1, //little endian mode
RI = 0x2,
DR = 0x10,
IR = 0x20,
IP = 0x40,
FE1 = 0x100,
BE = 0x200,
SE = 0x400,
FE0 = 0x800,
ME = 0x1000,
FP = 0x2000,
PR = 0x4000,
EE = 0x8000, //external interrupt
ILE = 0x10000,
POW = 0x40000
// ----------------------------------------------------------------------------------------
// 64-bit // 32-bit // Notes for MPC601 (601), PowerPC (PPC),
// // // MPC750 (750), Altivec (AV), Power ISA (ISA)
// ----------------------------------------------------------------------------------------
LE = (1 << (63 - 63)), // 31 // Little-endian mode enable (not 601);
// Little-Endian Mode (ISA)
RI = (1 << (63 - 62)), // 30 // Recoverable exception (not 601);
// Recoverable Interrupt (ISA)
PM = (1 << (63 - 61)), // 29 // Performance monitor marked mode (750);
// Performance Monitor Mark (PMM for ISA)
// = (1 << (63 - 60)), // 28 // Reserved
DR = (1 << (63 - 59)), // 27 // Data address translation (DT on 601);
// Data Relocate (ISA)
IR = (1 << (63 - 58)), // 26 // Instruction address translation (IT on 601);
// Instruction Relocate (ISA)
IP = (1 << (63 - 57)), // 25 // Exception prefix (EP); Reserved (ISA)
// = (1 << (63 - 56)), // 24 // Reserved (AL for POWER)
FE1 = (1 << (63 - 55)), // 23 // Floating-point exception mode 1
BE = (1 << (63 - 54)), // 22 // Branch trace enable (Optional, not 601);
// Trace Enable (TE): Branch Trace (ISA)
SE = (1 << (63 - 53)), // 21 // Single-step trace enable (Optional);
// Trace Enable (TE): Single Step Trace (ISA)
FE0 = (1 << (63 - 52)), // 20 // Floating-point exception mode 0
ME = (1 << (63 - 51)), // 19 // Machine check enable;
// Machine Check Interrupt Enable (ISA)
FP = (1 << (63 - 50)), // 18 // Floating-point available
PR = (1 << (63 - 49)), // 17 // Privilege level; Problem State (ISA)
EE = (1 << (63 - 48)), // 16 // External exception enable (601);
// External interrupt enable
// ----------------------------------------------------------------------------------------
ILE = (1 << (63 - 47)), // 15 // Exception little-endian mode (not 601, not ISA)
TGPR = (1 << (63 - 46)), // 14 // Temporary GPR remapping (603e)
POW = (1 << (63 - 45)), // 13 // Power management enable (not 601, not ISA)
// = (1 << (63 - 44)), // 12 // Reserved
// = (1 << (63 - 42)), // 10 // Reserved
// S = (1 << (63 - 41)), // 9 // Secure (ISA)
// VSX = (1 << (63 - 40)), // 8 // VSX Available (ISA)
// = (1 << (63 - 39)), // 7 // Reserved
VEC = (1 << (63 - 38)), // 6 // AltiVec available (AV); Vector Available (ISA)
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// HV = (1ULL << (63 - 3)), // // Hypervisor State (ISA)
// ISF = (1ULL << (63 - 2)), // // Exception 64-bit mode (optional, PPC)
// = (1ULL << (63 - 1)), // // Reserved
// SF = (1ULL << (63 - 0)), // // Sixty-four bit mode (PowerPC, PowerISA)
// ----------------------------------------------------------------------------------------
};
enum XER : uint32_t {
+62 -51
View File
@@ -92,6 +92,7 @@ uint64_t rtc_timestamp; // stores vCPU virtual time of the last RTC write
uint64_t tbr_wr_value; // last value written to the TBR
uint32_t tbr_freq_ghz; // TBR/RTC driving frequency in GHz expressed as a
// 32 bit fraction less than 1.0 (999.999999 MHz maximum).
uint32_t tbr_freq_shift; // If 32 bits is not sufficient, then include a shift.
uint64_t tbr_period_ns; // TBR/RTC period in ns expressed as a 64 bit value
// with 32 fractional bits (<1 Hz minimum).
uint64_t timebase_counter; // internal timebase counter
@@ -445,86 +446,80 @@ Opcode table macros:
- r is for raw (adding custom entries to the table)
*/
#define OPr(opcode, mod, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | (mod)] = fn; \
} while (0)
#define OPr_fp(opcode, mod, fn) \
do { \
OPr(opcode, mod, fn); \
OpcodeGrabberNoFPU[((opcode) << 11) | (mod)] = ppc_fpu_off; \
} while (0)
#define OP(opcode, fn) \
do { \
for (uint32_t mod = 0; mod < 2048; mod++) { \
OpcodeGrabber[((opcode) << 11) | mod] = fn; \
} \
for (uint32_t mod = 0; mod < 2048; mod++) { \
OPr(opcode, mod, fn); \
} \
} while (0)
#define OP_fp(opcode, fn) \
do { \
for (uint32_t mod = 0; mod < 2048; mod++) { \
OpcodeGrabber[((opcode) << 11) | mod] = fn; \
OpcodeGrabberNoFPU[((opcode) << 11) | mod] = ppc_fpu_off; \
} \
for (uint32_t mod = 0; mod < 2048; mod++) { \
OPr_fp(opcode, mod, fn); \
} \
} while (0)
#define OPX(opcode, subopcode, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1)] = fn; \
} while (0)
#define OPX(opcode, subopcode, fn) OPr(opcode, (subopcode)<<1, fn)
#define OPX_fp(opcode, subopcode, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1)] = fn; \
OpcodeGrabberNoFPU[((opcode) << 11) | ((subopcode)<<1)] = ppc_fpu_off; \
} while (0)
#define OPX_fp(opcode, subopcode, fn) OPr_fp(opcode, (subopcode)<<1, fn)
#define OPXd(opcode, subopcode, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<RC0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<RC1>; \
OPr(opcode, ((subopcode)<<1) | 0, fn<RC0>); \
OPr(opcode, ((subopcode)<<1) | 1, fn<RC1>); \
} while (0)
#define OPXd_fp(opcode, subopcode, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<RC0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<RC1>; \
OpcodeGrabberNoFPU[((opcode) << 11) | ((subopcode)<<1) | 0x000] = ppc_fpu_off; \
OpcodeGrabberNoFPU[((opcode) << 11) | ((subopcode)<<1) | 0x001] = ppc_fpu_off; \
OPr_fp(opcode, ((subopcode)<<1) | 0, fn<RC0>); \
OPr_fp(opcode, ((subopcode)<<1) | 1, fn<RC1>); \
} while (0)
#define OPXod(opcode, subopcode, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<RC0, OV0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<RC1, OV0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x400] = fn<RC0, OV1>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x401] = fn<RC1, OV1>; \
OPr(opcode, ((subopcode)<<1) | 0x000, (fn<RC0, OV0>)); \
OPr(opcode, ((subopcode)<<1) | 0x001, (fn<RC1, OV0>)); \
OPr(opcode, ((subopcode)<<1) | 0x400, (fn<RC0, OV1>)); \
OPr(opcode, ((subopcode)<<1) | 0x401, (fn<RC1, OV1>)); \
} while (0)
#define OPXdc(opcode, subopcode, fn, carry) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<carry, RC0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<carry, RC1>; \
OPr(opcode, ((subopcode)<<1) | 0, (fn<carry, RC0>)); \
OPr(opcode, ((subopcode)<<1) | 1, (fn<carry, RC1>)); \
} while (0)
#define OPXdc_fp(opcode, subopcode, fn, carry) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<carry, RC0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<carry, RC1>; \
OpcodeGrabberNoFPU[((opcode) << 11) | ((subopcode)<<1) | 0x000] = ppc_fpu_off; \
OpcodeGrabberNoFPU[((opcode) << 11) | ((subopcode)<<1) | 0x001] = ppc_fpu_off; \
OPr_fp(opcode, ((subopcode)<<1) | 0, (fn<carry, RC0>)); \
OPr_fp(opcode, ((subopcode)<<1) | 1, (fn<carry, RC1>)); \
} while (0)
#define OPXcod(opcode, subopcode, fn, carry) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<carry, RC0, OV0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<carry, RC1, OV0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x400] = fn<carry, RC0, OV1>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x401] = fn<carry, RC1, OV1>; \
OPr(opcode, ((subopcode)<<1) | 0x000, (fn<carry, RC0, OV0>)); \
OPr(opcode, ((subopcode)<<1) | 0x001, (fn<carry, RC1, OV0>)); \
OPr(opcode, ((subopcode)<<1) | 0x400, (fn<carry, RC0, OV1>)); \
OPr(opcode, ((subopcode)<<1) | 0x401, (fn<carry, RC1, OV1>)); \
} while (0)
#define OPla(opcode, subopcode, fn) \
do { \
for (uint32_t mod = 0; mod < 512; mod++) { \
OpcodeGrabber[((opcode) << 11) | (mod << 2) | (subopcode)] = fn; \
} \
} while (0)
#define OPr(opcode, mod, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | (mod)] = fn; \
for (uint32_t mod = 0; mod < 512; mod++) { \
OPr(opcode, (mod << 2) | (subopcode), fn); \
} \
} while (0)
#define OP31(subopcode, fn) OPX(31, subopcode, fn)
@@ -538,10 +533,7 @@ do { \
#define OP63d(subopcode, fn) OPXd_fp(63, subopcode, fn)
#define OP63dc(subopcode, fn, carry) OPXdc_fp(63, subopcode, fn, carry)
#define OP59d(subopcode, fn) \
do { \
OPXd_fp(59, (subopcode), fn); \
} while (0)
#define OP59d(subopcode, fn) OPXd_fp(59, (subopcode), fn)
#define OP59cd(subopcode, fn) \
do { \
@@ -835,12 +827,31 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool do_include_6
#endif
g_nanoseconds_base = cpu_now_ns();
g_icycles = 0;
//icnt_factor = 6;
icnt_factor = 4;
// // // PDM cpu clock calculated at 0x403036CC in r3
// icnt_factor = 11; // 1 instruction = 2048 ns = 0.488 MHz // 00068034 = 0.426036 MHz = 2347.219 ns // floppy doesn't work
// icnt_factor = 10; // 1 instruction = 1024 ns = 0.977 MHz // 000D204C = 0.860236 MHz = 1162.471 ns // [0..10] MHz = invalid clock for PDM gestalt calculation
// icnt_factor = 9; // 1 instruction = 512 ns = 1.953 MHz // 001A6081 = 1.728641 MHz = 578.489 ns // [0..10] MHz = invalid clock for PDM gestalt calculation
// icnt_factor = 8; // 1 instruction = 256 ns = 3.906 MHz // 0034E477 = 3.466359 MHz = 288.487 ns // [0..10] MHz = invalid clock for PDM gestalt calculation
// icnt_factor = 7; // 1 instruction = 128 ns = 7.813 MHz // 0069E54C = 6.939980 MHz = 144.092 ns // [0..10] MHz = invalid clock for PDM gestalt calculation
// icnt_factor = 6; // 1 instruction = 64 ns = 15.625 MHz // 00D3E6F5 = 13.887221 MHz = 72.008 ns // (10..60] = 50, (60..73] = 66, (73..100] = 80 MHz
// icnt_factor = 5; // 1 instruction = 32 ns = 31.250 MHz // 01A7B672 = 27.768434 MHz = 36.012 ns //
icnt_factor = 4; // 1 instruction = 16 ns = 62.500 MHz // 034F0F0F = 55.512847 MHz = 18.013 ns // 6100/60 in Apple System Profiler
// icnt_factor = 3; // 1 instruction = 8 ns = 125.000 MHz // 069E1E1E = 111.025694 MHz = 9.006 ns // (100...) MHz = invalid clock for PDM gestalt calculation
// icnt_factor = 2; // 1 instruction = 4 ns = 250.000 MHz // 0D3C3C3C = 222.051388 MHz = 4.503 ns // (100...) MHz = invalid clock for PDM gestalt calculation
// icnt_factor = 1; // 1 instruction = 2 ns = 500.000 MHz // 1A611A7B = 442.571387 MHz = 2.259 ns // (100...) MHz = invalid clock for PDM gestalt calculation
// icnt_factor = 0; // 1 instruction = 1 ns = 1500.000 MHz // 3465B2D9 = 879.080153 MHz = 1.137 ns // (100...) MHz = invalid clock for PDM gestalt calculation
tbr_wr_timestamp = 0;
rtc_timestamp = 0;
tbr_wr_value = 0;
tbr_freq_ghz = (tb_freq << 32) / NS_PER_SEC;
if (is_601)
tb_freq <<= 7;
tbr_freq_shift = 0;
uint64_t x;
for (x = (tb_freq << 32) / NS_PER_SEC; x >> 32; x >>= 1)
tbr_freq_shift++;
tbr_freq_ghz = (uint32_t)x;
tbr_period_ns = ((uint64_t)NS_PER_SEC << 32) / tb_freq;
exec_flags = 0;
+2 -4
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -154,9 +154,7 @@ static void ppc_update_vx() {
}
static void ppc_update_fex() {
uint32_t fpscr_check = (((ppc_state.fpscr >> 25) & 0x1F) &
((ppc_state.fpscr >> 3) & 0x1F));
uint32_t fpscr_check = (ppc_state.fpscr >> 22) & ppc_state.fpscr & 0x0F8;
if (fpscr_check)
ppc_state.fpscr |= VX;
else
+56 -5
View File
@@ -311,6 +311,7 @@ MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size, bool allow_mmio) {
uint32_t dev_base = 0;
bool is_writable;
AddressMapEntry *cur_dma_rgn;
AddressMapEntry *next_dma_rgn;
cur_dma_rgn = mem_ctrl_instance->find_range(addr);
if (!cur_dma_rgn) {
@@ -320,9 +321,44 @@ MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size, bool allow_mmio) {
}
if (addr + size - 1 > cur_dma_rgn->end) {
ABORT_F("SOS: DMA access to unmapped physical memory 0x%08X..0x%08X because size extends outside region 0x%08X..0x%08X!",
addr, addr + size - 1, cur_dma_rgn->start, cur_dma_rgn->end
);
if (cur_dma_rgn->type & (RT_ROM | RT_RAM))
LOG_F(WARNING, "this region: 0x%08X..0x%08X (host: 0x%08llX..0x%08llX)",
cur_dma_rgn->start, cur_dma_rgn->end,
uint64_t(cur_dma_rgn->mem_ptr),
uint64_t(cur_dma_rgn->mem_ptr + cur_dma_rgn->end - cur_dma_rgn->start)
);
else
LOG_F(ERROR, "this region: 0x%08X..0x%08X",
cur_dma_rgn->start, cur_dma_rgn->end
);
next_dma_rgn = mem_ctrl_instance->find_range(cur_dma_rgn->end + 1);
if (next_dma_rgn) {
if (next_dma_rgn->type & (RT_ROM | RT_RAM))
LOG_F(WARNING, "next region: 0x%08X..0x%08X (host: 0x%08llX..0x%08llX)",
next_dma_rgn->start, next_dma_rgn->end,
uint64_t(next_dma_rgn->mem_ptr),
uint64_t(next_dma_rgn->mem_ptr + next_dma_rgn->end - next_dma_rgn->start)
);
else
LOG_F(ERROR, "next region: 0x%08X..0x%08X",
next_dma_rgn->start, next_dma_rgn->end
);
}
if (next_dma_rgn &&
(cur_dma_rgn->type & (RT_ROM | RT_RAM)) &&
((cur_dma_rgn->type & (RT_ROM | RT_RAM)) == (next_dma_rgn->type & (RT_ROM | RT_RAM))) &&
(next_dma_rgn->mem_ptr == cur_dma_rgn->mem_ptr + cur_dma_rgn->end - cur_dma_rgn->start + 1) &&
(addr + size - 1 <= next_dma_rgn->end)
) {
LOG_F(INFO, "DMA to physical memory 0x%08X..0x%08X is OK!"
" The regions are the same type and adjacent in host and guest spaces.",
addr, addr + size - 1
);
} else {
ABORT_F("SOS: DMA access to unmapped physical memory 0x%08X..0x%08X because size extends outside region!",
addr, addr + size - 1
);
}
}
if ((cur_dma_rgn->type & RT_MMIO) && !allow_mmio) {
@@ -1447,7 +1483,8 @@ uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size) {
default:
ret_val = mmu_read_vmem<uint8_t>(NO_OPCODE, virt_addr);
}
} catch (std::invalid_argument& exc) {
}
catch (std::invalid_argument& exc) {
/* restore MMU-related CPU state */
mmu_exception_handler = ppc_exception_handler;
ppc_state.spr[SPR::DSISR] = save_dsisr;
@@ -1456,6 +1493,15 @@ uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size) {
/* rethrow MMU exception */
throw exc;
}
catch (...) {
/* restore MMU-related CPU state */
mmu_exception_handler = ppc_exception_handler;
ppc_state.spr[SPR::DSISR] = save_dsisr;
ppc_state.spr[SPR::DAR] = save_dar;
/* rethrow MMU exception */
throw(false);
}
/* restore MMU-related CPU state */
mmu_exception_handler = ppc_exception_handler;
@@ -1549,7 +1595,12 @@ bool mmu_translate_dbg(uint32_t guest_va, uint32_t &guest_pa) {
guest_pa = tlb1_entry->phys_tag | (guest_va & 0xFFFUL);
is_mapped = true;
} while (0);
} catch (std::invalid_argument& exc) {
}
catch (std::invalid_argument& exc) {
LOG_F(WARNING, "Unmapped address 0x%08X", guest_va);
is_mapped = false;
}
catch (...) {
LOG_F(WARNING, "Unmapped address 0x%08X", guest_va);
is_mapped = false;
}
+69 -41
View File
@@ -21,6 +21,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
// General opcodes for the processor - ppcopcodes.cpp
#include <core/bitops.h>
#include <core/timermanager.h>
#include <core/mathutils.h>
#include "ppcemu.h"
@@ -684,10 +685,9 @@ void dppc_interpreter::ppc_rlwimi(uint32_t opcode) {
unsigned rot_mb = (opcode >> 6) & 0x1F;
unsigned rot_me = (opcode >> 1) & 0x1F;
uint32_t mask = rot_mask(rot_mb, rot_me);
uint32_t r = rot_sh ? ((ppc_result_d << rot_sh) |
(ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
uint32_t r = ROTL_32(ppc_result_d, rot_sh);
ppc_result_a = (ppc_result_a & ~mask) | (r & mask);
if ((opcode & 0x01) == 1) {
if (opcode & 1) {
ppc_changecrf0(ppc_result_a);
}
ppc_store_iresult_reg(reg_a, ppc_result_a);
@@ -698,10 +698,9 @@ void dppc_interpreter::ppc_rlwinm(uint32_t opcode) {
unsigned rot_mb = (opcode >> 6) & 0x1F;
unsigned rot_me = (opcode >> 1) & 0x1F;
uint32_t mask = rot_mask(rot_mb, rot_me);
uint32_t r = rot_sh ? ((ppc_result_d << rot_sh) |
(ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
uint32_t r = ROTL_32(ppc_result_d, rot_sh);
ppc_result_a = r & mask;
if ((opcode & 0x01) == 1) {
if (opcode & 1) {
ppc_changecrf0(ppc_result_a);
}
ppc_store_iresult_reg(reg_a, ppc_result_a);
@@ -709,15 +708,12 @@ void dppc_interpreter::ppc_rlwinm(uint32_t opcode) {
void dppc_interpreter::ppc_rlwnm(uint32_t opcode) {
ppc_grab_regssab(opcode);
ppc_result_b &= 0x1F;
unsigned rot_mb = (opcode >> 6) & 0x1F;
unsigned rot_me = (opcode >> 1) & 0x1F;
uint32_t mask = rot_mask(rot_mb, rot_me);
uint32_t rot = ppc_result_b & 0x1F;
uint32_t r = rot ? ((ppc_result_d << rot) |
(ppc_result_d >> (32 - rot))) : ppc_result_d;
uint32_t r = ROTL_32(ppc_result_d, ppc_result_b);
ppc_result_a = r & mask;
if ((opcode & 0x01) == 1) {
if (opcode & 1) {
ppc_changecrf0(ppc_result_a);
}
ppc_store_iresult_reg(reg_a, ppc_result_a);
@@ -819,6 +815,7 @@ void dppc_interpreter::ppc_mtmsr(uint32_t opcode) {
}
}
#if 0
static inline void calc_rtcl_value()
{
uint64_t new_ts = get_virt_time_ns();
@@ -832,22 +829,47 @@ static inline void calc_rtcl_value()
}
rtc_timestamp = new_ts;
}
#else
static inline void calc_rtcl_value()
{
uint64_t adj;
uint32_t adj_lo;
uint64_t new_ts = get_virt_time_ns();
uint64_t diff = new_ts - rtc_timestamp;
_u32xu64(tbr_freq_ghz, diff, adj, adj_lo);
if (tbr_freq_shift)
adj = (adj << tbr_freq_shift) + (adj_lo >> (32 - tbr_freq_shift));
uint64_t rtc_l = adj + rtc_lo;
if (rtc_l >= ONE_BILLION_NS) { // check RTCL overflow
rtc_hi += (uint32_t)(rtc_l / ONE_BILLION_NS);
rtc_lo = rtc_l % ONE_BILLION_NS;
}
else {
rtc_lo = (uint32_t)rtc_l;
}
rtc_timestamp = new_ts;
}
#endif
static inline uint64_t calc_tbr_value()
{
uint64_t tbr_inc;
uint32_t tbr_inc_lo;
uint64_t adj;
uint32_t adj_lo;
uint64_t diff = get_virt_time_ns() - tbr_wr_timestamp;
_u32xu64(tbr_freq_ghz, diff, tbr_inc, tbr_inc_lo);
return (tbr_wr_value + tbr_inc);
_u32xu64(tbr_freq_ghz, diff, adj, adj_lo);
if (tbr_freq_shift)
adj = (adj << tbr_freq_shift) + (adj_lo >> (32 - tbr_freq_shift));
return (tbr_wr_value + adj);
}
static inline uint32_t calc_dec_value() {
uint64_t dec_adj;
uint32_t dec_adj_lo;
uint64_t adj;
uint32_t adj_lo;
uint64_t diff = get_virt_time_ns() - dec_wr_timestamp;
_u32xu64(tbr_freq_ghz, diff, dec_adj, dec_adj_lo);
return (dec_wr_value - static_cast<uint32_t>(dec_adj));
_u32xu64(tbr_freq_ghz, diff, adj, adj_lo);
if (tbr_freq_shift)
adj = (adj << tbr_freq_shift) + (adj_lo >> (32 - tbr_freq_shift));
return (dec_wr_value - static_cast<uint32_t>(adj));
}
static void update_timebase(uint64_t mask, uint64_t new_val)
@@ -943,8 +965,13 @@ void dppc_interpreter::ppc_mfspr(uint32_t opcode) {
}
// fallthrough
case SPR::DEC_S:
ppc_state.gpr[reg_d] = ppc_state.spr[SPR::DEC_S] = calc_dec_value();
{
uint32_t val = calc_dec_value();
if (is_601)
val &= ~0x7F;
ppc_state.gpr[reg_d] = ppc_state.spr[SPR::DEC_S] = val;
break;
}
default:
// FIXME: Unknown SPR should be noop or illegal instruction.
ppc_state.gpr[reg_d] = ppc_state.spr[ref_spr];
@@ -1000,6 +1027,8 @@ void dppc_interpreter::ppc_mtspr(uint32_t opcode) {
ppc_state.spr[RTCU_S] = rtc_hi = val;
break;
case SPR::DEC_S:
if (is_601)
val &= ~0x7F;
ppc_state.spr[DEC_S] = val;
update_decrementer(val);
break;
@@ -1383,27 +1412,26 @@ void dppc_interpreter::ppc_rfi(uint32_t opcode) {
return;
}
uint32_t old_msr_val = ppc_state.msr;
uint32_t new_srr1_val = (ppc_state.spr[SPR::SRR1] & 0x87C0FF73UL);
uint32_t new_msr_val = (ppc_state.msr & ~0x87C0FF73UL);
// keep 0, 5-9, 16-23, 25-27, 30-31 bits; exclude POW, ILE, and Reserved bits.
const uint32_t msr_bits_to_replace = 0x87C0FF73UL;
const uint32_t msr_bits_to_clear = MSR::POW;
new_msr_val = (new_msr_val | new_srr1_val) & 0xFFFBFFFFUL;
ppc_msr_did_change(old_msr_val, new_msr_val);
uint32_t bits_from_srr1 = ppc_state.spr[SPR::SRR1] &
(msr_bits_to_replace & ~msr_bits_to_clear);
uint32_t new_msr_val = (ppc_state.msr & ~(msr_bits_to_replace | msr_bits_to_clear)) |
bits_from_srr1;
// generate External Interrupt Exception
// if CPU interrupt line is still asserted
if (ppc_state.msr & MSR::EE && int_pin) {
ppc_msr_did_change(ppc_state.msr, new_msr_val);
// setting MSR[EE] may enable pending exceptions
if ((ppc_state.msr & MSR::EE) && (int_pin || dec_exception_pending)) {
uint32_t save_srr0 = ppc_state.spr[SPR::SRR0] & ~3UL;
ppc_exception_handler(Except_Type::EXC_EXT_INT, 0);
ppc_state.spr[SPR::SRR0] = save_srr0;
return;
}
if ((ppc_state.msr & MSR::EE) && dec_exception_pending) {
dec_exception_pending = false;
//LOG_F(WARNING, "decrementer exception from rfi msr:0x%X", ppc_state.msr);
uint32_t save_srr0 = ppc_state.spr[SPR::SRR0] & ~3UL;
ppc_exception_handler(Except_Type::EXC_DECR, 0);
if (int_pin) // check for pending external exceptions (higher priority)
ppc_exception_handler(Except_Type::EXC_EXT_INT, 0);
else {
dec_exception_pending = false;
ppc_exception_handler(Except_Type::EXC_DECR, 0);
}
ppc_state.spr[SPR::SRR0] = save_srr0;
return;
}
@@ -1551,10 +1579,10 @@ void dppc_interpreter::ppc_stu(uint32_t opcode) {
ea += ppc_result_a;
mmu_write_vmem<T>(opcode, ea, ppc_result_d);
ppc_state.gpr[reg_a] = ea;
}
}
else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
}
@@ -1576,7 +1604,7 @@ void dppc_interpreter::ppc_stux(uint32_t opcode) {
}
else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
}
template void dppc_interpreter::ppc_stux<uint8_t>(uint32_t opcode);
+4
View File
@@ -313,6 +313,10 @@ def gen_rot_opcode(opc_str, sh, mb, me):
return (0x15 << 26) + (4 << 21) + (3 << 16) + (sh << 11) + (mb << 6) + (me << 1)
elif opc_str == "RLWINM.":
return (0x15 << 26) + (4 << 21) + (3 << 16) + (sh << 11) + (mb << 6) + (me << 1) + 1
elif opc_str == "RLWNM":
return (0x17 << 26) + (4 << 21) + (3 << 16) + (3 << 11) + (mb << 6) + (me << 1)
elif opc_str == "RLWNM.":
return (0x17 << 26) + (4 << 21) + (3 << 16) + (3 << 11) + (mb << 6) + (me << 1) + 1
def extract_imm(line):
pos = 12
+1 -1
View File
@@ -73,7 +73,7 @@ static vector<PPCDisasmContext> read_test_data() {
/* put instruction mnemonic padded with trailing spaces */
idisasm << tokens[2];
idisasm << setw(8 - (int)tokens[2].length()) << " ";
idisasm << setw(streamsize(8) - (int)tokens[2].length()) << " ";
/* now add comma-separated operands */
for (i = 3; i < tokens.size(); i++) {
+119 -23
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -51,6 +51,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
using namespace std;
#define COUTX uppercase << hex
#define COUT0_X(w) setfill('0') << setw(w) << right << COUTX
#define COUT016X COUT0_X(16)
#define COUT08X COUT0_X(8)
#define COUT04X COUT0_X(4)
static uint32_t str2addr(string& addr_str) {
try {
return static_cast<uint32_t>(stoul(addr_str, NULL, 0));
@@ -86,6 +92,10 @@ static void show_help() {
cout << " dump NT,X -- dump N memory cells of size T at address X" << endl;
cout << " T can be b(byte), w(word), d(double)," << endl;
cout << " q(quad) or c(character)." << endl;
cout << " setmem X=V.T -- set memory at address X to value V of size T" << endl;
cout << " T can be b(byte), w(word), d(double)," << endl;
cout << " q(quad) or c(character)." << endl;
cout << " regions -- dump memory regions" << endl;
cout << " profile C N -- run subcommand C on profile N" << endl;
cout << " supported subcommands:" << endl;
cout << " 'show' - show profile report" << endl;
@@ -129,7 +139,12 @@ static uint32_t disasm_68k(uint32_t count, uint32_t address) {
for (; power_on && count > 0; count--) {
// prefetch opcode bytes (a 68k instruction can occupy 2...12 bytes)
for (int i = 0; i < sizeof(code); i++) {
code[i] = mem_read_dbg(address + i, 1);
try {
code[i] = mem_read_dbg(address + i, 1);
}
catch(...) {
printf("<memerror>");
}
}
const uint8_t *code_ptr = code;
@@ -143,16 +158,16 @@ static uint32_t disasm_68k(uint32_t count, uint32_t address) {
}
if (cs_disasm_iter(cs_handle, &code_ptr, &code_size, &dis_addr, insn)) {
cout << uppercase << hex << insn->address << " ";
cout << COUTX << insn->address << " ";
cout << setfill(' ');
cout << setw(10) << left << insn->mnemonic << insn->op_str << endl;
cout << setw(10) << left << insn->mnemonic << insn->op_str << right << endl;
address = static_cast<uint32_t>(dis_addr);
} else {
print_bin:
cout << uppercase << hex << address << " ";
cout << COUTX << address << " ";
cout << setfill(' ');
cout << setw(10) << left << "dc.w" << "$" << hex <<
((code[0] << 8) | code[1]) << endl;
((code[0] << 8) | code[1]) << right << endl;
address += 2;
}
}
@@ -224,21 +239,22 @@ void print_68k_regs()
for (i = 0; i < 8; i++) {
reg = "R" + to_string(i + 8);
cout << "D" << dec << i << " : " << uppercase << hex << get_reg(reg) << endl;
cout << " D" << dec << i << " : " << COUT08X << get_reg(reg) << endl;
}
for (i = 0; i < 7; i++) {
reg = "R" + to_string(i + 16);
cout << "A" << dec << i << " : " << uppercase << hex << get_reg(reg) << endl;
cout << " A" << dec << i << " : " << COUT08X << get_reg(reg) << endl;
}
cout << "A7 : " << uppercase << hex << get_reg(string("R1")) << endl;
cout << " A7 : " << COUT08X << get_reg(string("R1")) << endl;
cout << "PC: " << uppercase << hex << get_reg(string("R24")) - 2 << endl;
cout << " PC : " << COUT08X << get_reg(string("R24")) - 2 << endl;
cout << "SR: " << uppercase << hex << ((get_reg("R25") & 0xFF) << 8) << endl;
cout << " SR : " << COUT08X << ((get_reg("R25") & 0xFF) << 8) << endl;
cout << "CCR: " << uppercase << hex << get_reg(string("R26")) << endl;
cout << " CCR : " << COUT08X << get_reg(string("R26")) << endl;
cout << dec << setfill(' ');
}
#endif // ENABLE_68K_DEBUGGER
@@ -324,8 +340,7 @@ static void dump_mem(string& params) {
cout << (char)val;
chars_per_line += cell_size;
} else {
cout << setw(cell_size * 2) << setfill('0') << right;
cout << uppercase << hex << val << " ";
cout << COUT0_X(cell_size * 2) << val << " ";
chars_per_line += cell_size * 2 + 2;
}
}
@@ -337,6 +352,79 @@ static void dump_mem(string& params) {
cout << endl << endl;
}
static void patch_mem(string& params) {
int value_size = 1;
uint32_t addr, value;
string addr_str, value_str, size_str;
if (params.find_first_of("=") == std::string::npos) {
cout << "setmem: not enough arguments specified. Try 'help'." << endl;
return;
}
addr_str = params.substr(0, params.find_first_of("="));
value_str = params.substr(params.find_first_of("=") + 1);
if (value_str.find_first_of(".") == std::string::npos) {
cout << "setmem: no value size specified. Try 'help'." << endl;
return;
}
size_str = value_str.substr(value_str.find_first_of(".") + 1);
value_str = value_str.substr(0, value_str.find_first_of("."));
switch (size_str.back()) {
case 'b':
case 'B':
value_size = 1;
break;
case 'w':
case 'W':
value_size = 2;
break;
case 'd':
case 'D':
value_size = 4;
break;
case 'q':
case 'Q':
value_size = 8;
break;
case 'c':
case 'C':
value_size = 1;
break;
default:
cout << "Invalid value size " << size_str << endl;
return;
}
try {
addr = str2addr(addr_str);
} catch (invalid_argument& exc) {
try {
// number conversion failed, trying reg name
addr = get_reg(addr_str);
} catch (invalid_argument& exc) {
cout << exc.what() << endl;
return;
}
}
try {
value = str2num(value_str);
} catch (invalid_argument& exc) {
cout << exc.what() << endl;
return;
}
try {
mem_write_dbg(addr, value, value_size);
} catch (invalid_argument& exc) {
cout << exc.what() << endl;
}
}
static uint32_t disasm(uint32_t count, uint32_t address) {
PPCDisasmContext ctx;
@@ -345,9 +433,9 @@ static uint32_t disasm(uint32_t count, uint32_t address) {
for (int i = 0; power_on && i < count; i++) {
ctx.instr_code = READ_DWORD_BE_A(mmu_translate_imem(ctx.instr_addr));
cout << setfill('0') << setw(8) << right << uppercase << hex << ctx.instr_addr;
cout << ": " << setfill('0') << setw(8) << right << uppercase << hex << ctx.instr_code;
cout << " " << disassemble_single(&ctx) << setfill(' ') << left << endl;
cout << COUT08X << ctx.instr_addr;
cout << ": " << COUT08X << ctx.instr_code;
cout << " " << disassemble_single(&ctx) << setfill(' ') << right << endl;
}
return ctx.instr_addr;
}
@@ -360,7 +448,7 @@ static void print_gprs() {
reg_name = "r" + to_string(i);
cout << right << std::setw(5) << setfill(' ') << reg_name << " : " <<
setw(8) << setfill('0') << right << uppercase << hex << get_reg(reg_name) << setfill(' ');
COUT08X << get_reg(reg_name) << setfill(' ');
if (i & 1) {
cout << endl;
@@ -373,7 +461,7 @@ static void print_gprs() {
for (auto &spr : sprs) {
cout << right << std::setw(5) << setfill(' ') << spr << " : " <<
setw(8) << setfill('0') << uppercase << hex << get_reg(spr) << setfill(' ');
COUT08X << get_reg(spr) << setfill(' ');
if (i & 1) {
cout << endl;
@@ -390,11 +478,11 @@ static void print_fprs() {
for (int i = 0; i < 32; i++) {
reg_name = "f" + to_string(i);
cout << right << std::setw(6) << setfill(' ') << reg_name << " : " <<
setw(16) << setfill('0') << right << uppercase << hex << ppc_state.fpr[i].int64_r <<
COUT016X << ppc_state.fpr[i].int64_r <<
" = " << left << setfill(' ') << ppc_state.fpr[i].dbl64_r << endl;
}
cout << right << std::setw(6) << setfill(' ') << "fpscr" << " : " <<
setw(8) << setfill('0') << uppercase << hex << ppc_state.fpscr << setfill(' ') << endl;
COUT08X << ppc_state.fpscr << setfill(' ') << endl;
}
extern bool is_601;
@@ -487,7 +575,7 @@ void DppcDebugger::enter_debugger() {
#ifndef _WIN32
struct winsize win_size_previous;
ioctl(0, TIOCGWINSZ, &win_size_previous);
ioctl(STDIN_FILENO, TIOCGWINSZ, &win_size_previous);
#endif
while (1) {
@@ -547,7 +635,7 @@ void DppcDebugger::enter_debugger() {
#ifndef _WIN32
struct winsize win_size_current;
ioctl(0, TIOCGWINSZ, &win_size_current);
ioctl(STDIN_FILENO, TIOCGWINSZ, &win_size_current);
if (win_size_current.ws_col != win_size_previous.ws_col || win_size_current.ws_row != win_size_previous.ws_row) {
win_size_previous = win_size_current;
if (cmd.empty()) {
@@ -785,6 +873,10 @@ void DppcDebugger::enter_debugger() {
expr_str = "";
ss >> expr_str;
dump_mem(expr_str);
} else if (cmd == "setmem") {
expr_str = "";
ss >> expr_str;
patch_mem(expr_str);
#ifdef ENABLE_68K_DEBUGGER
} else if (cmd == "context") {
cmd = "";
@@ -798,6 +890,10 @@ void DppcDebugger::enter_debugger() {
cout << "Unknown debugging context: " << expr_str << endl;
}
#endif
} else if (cmd == "regions") {
cmd = "";
if (mem_ctrl_instance)
mem_ctrl_instance->dump_regions();
} else if (cmd == "printenv") {
cmd = "";
if (ofnvram->init())
+2
View File
@@ -9,11 +9,13 @@ platform_glob(SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/adb/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/clockgen/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/firewire/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/i2c/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/ata/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/nubus/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/pci/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/scsi/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/usb/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ethernet/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/floppy/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ioctrl/*.cpp"
+16 -4
View File
@@ -27,6 +27,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <loguru.hpp>
#include <cinttypes>
#include <core/timermanager.h>
using namespace ata_interface;
@@ -75,7 +76,8 @@ uint16_t AtaBaseDevice::read(const uint8_t reg_addr) {
this->r_status &= ~DRQ;
} else {
this->chunk_cnt = std::min(this->xfer_cnt, this->chunk_size);
this->update_intrq(1);
TimerManager::get_instance()->add_oneshot_timer(
USECS_TO_NSECS(100), [this]() { this->update_intrq(1); });
}
}
return ret_data;
@@ -117,12 +119,18 @@ void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
if (this->xfer_cnt <= 0) { // transfer complete?
this->xfer_cnt = 0;
this->r_status &= ~DRQ;
this->r_status &= ~BSY;
this->update_intrq(1);
//LOG_F(INFO, "%s: write complete", name.c_str());
TimerManager::get_instance()->add_oneshot_timer(USECS_TO_NSECS(100), [this]() {
this->r_status &= ~BSY;
this->update_intrq(1);
});
} else {
this->cur_data_ptr = this->data_ptr;
this->chunk_cnt = std::min(this->xfer_cnt, this->chunk_size);
this->signal_data_ready();
//LOG_F(INFO, "%s: write needs more data (left: 0x%x)", name.c_str(), xfer_cnt);
TimerManager::get_instance()->add_oneshot_timer(USECS_TO_NSECS(100), [this]() {
this->signal_data_ready();
});
}
}
}
@@ -146,6 +154,10 @@ void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
this->r_dev_head = value;
break;
case ATA_Reg::COMMAND:
if ((this->r_status & BSY) != 0) {
LOG_F(ERROR, "%s: tried to perform command %x when busy", name.c_str(), value);
break;
}
this->r_command = value;
if (is_selected() || this->r_command == DIAGNOSTICS) {
perform_command();
-1
View File
@@ -87,7 +87,6 @@ uint16_t AtapiBaseDevice::read(const uint8_t reg_addr) {
return this->r_dev_head;
case ATA_Reg::STATUS:
this->update_intrq(0);
return this->r_status;
case ATA_Reg::ALT_STATUS:
if (this->r_status & BSY && this->data_available()) {
this->r_byte_count = this->request_data();
+50 -1
View File
@@ -31,6 +31,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <memaccess.h>
#include <string>
#include <core/timermanager.h>
using namespace ata_interface;
@@ -157,6 +158,14 @@ void AtapiCdrom::perform_packet_command() {
case ScsiCommand::READ_6:
lba = this->cmd_pkt[1] << 16 | READ_WORD_BE_U(&this->cmd_pkt[2]);
xfer_len = this->cmd_pkt[4];
// if transfer length is zero then just complete command
if (xfer_len == 0) {
this->status_good();
this->present_status();
break;
}
if (this->r_features & ATAPI_Features::DMA) {
LOG_F(WARNING, "ATAPI DMA transfer requsted");
}
@@ -168,8 +177,23 @@ void AtapiCdrom::perform_packet_command() {
this->data_out_phase();
break;
case ScsiCommand::READ_10:
if (this->xfer_cnt > 0) {
LOG_F(ERROR, "%s: READ(10) when transfer already in progress", name.c_str());
this->status_error(ScsiSense::NOT_READY, ScsiError::DEV_NOT_READY);
this->present_status();
break;
}
lba = READ_DWORD_BE_U(&this->cmd_pkt[2]);
xfer_len = READ_WORD_BE_U(&this->cmd_pkt[7]);
// if transfer length is zero then just complete command
if (xfer_len == 0) {
this->status_good();
this->present_status();
break;
}
if (this->r_features & ATAPI_Features::DMA) {
LOG_F(WARNING, "ATAPI DMA transfer requsted");
}
@@ -178,11 +202,24 @@ void AtapiCdrom::perform_packet_command() {
this->r_byte_count = this->xfer_cnt;
this->data_ptr = (uint16_t*)this->data_cache.get();
this->status_good();
this->data_out_phase();
#if 0
TimerManager::get_instance()->add_oneshot_timer(
USECS_TO_NSECS(100), [this]() { this->data_out_phase(); });
#else
this->data_out_phase();
#endif
break;
case ScsiCommand::READ_12:
lba = READ_DWORD_BE_U(&this->cmd_pkt[2]);
xfer_len = READ_DWORD_BE_U(&this->cmd_pkt[6]);
// if transfer length is zero then just complete command
if (xfer_len == 0) {
this->status_good();
this->present_status();
break;
}
if (this->r_features & ATAPI_Features::DMA) {
LOG_F(WARNING, "ATAPI DMA transfer requsted");
}
@@ -203,6 +240,18 @@ void AtapiCdrom::perform_packet_command() {
{
lba = READ_DWORD_BE_U(&this->cmd_pkt[2]);
xfer_len = (this->cmd_pkt[6] << 16) | READ_WORD_BE_U(&this->cmd_pkt[7]);
if (this->cmd_pkt[9] == 0 && (this->cmd_pkt[10] & 7) == 0) {
// Treat as a non-data command.
xfer_len = 0;
}
// if transfer length is zero then just complete command
if (xfer_len == 0) {
this->status_good();
this->present_status();
break;
}
if (this->cmd_pkt[1] || (this->cmd_pkt[9] & ~0xf8) || ((this->cmd_pkt[9] & 0xf8) == 0) || this->cmd_pkt[10])
LOG_F(WARNING, "%s: unsupported READ_CD params: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X",
this->name.c_str(),
+2 -2
View File
@@ -118,7 +118,7 @@ int AthensClocks::get_dot_freq()
return 0;
}
float out_freq = 0.0f;
float out_freq = 50000000.0; // for 800x600 72Hz
int d2 = this->regs[AthensRegs::D2];
int n2 = this->regs[AthensRegs::N2];
@@ -150,7 +150,7 @@ int AthensClocks::get_dot_freq()
break;
}
LOG_F(INFO, "%s: dot clock frequency set to %f Hz", this->name.c_str(), out_freq);
LOG_F(INFO, "%s: dot clock frequency set to %f MHz", this->name.c_str(), out_freq / 1000000.0);
return static_cast<int>(out_freq + 0.5f);
}
+23 -3
View File
@@ -88,7 +88,7 @@ uint8_t DMAChannel::interpret_cmd() {
LOG_F(ERROR, "%s: Key > 0 not implemented", this->get_name().c_str());
break;
}
this->queue_len = cmd_struct.req_count;
this->queue_len = cmd_struct.req_count;
if (this->queue_len) {
res = mmu_map_dma_mem(cmd_struct.address, cmd_struct.req_count, false);
this->queue_data = res.host_va;
@@ -427,7 +427,8 @@ void DMAChannel::xfer_from_device() {
this->xfer_dir = DMA_DIR_FROM_DEV;
if (!this->dev_obj->xfer_from(this->queue_data, this->queue_len)) {
int got_bytes = this->dev_obj->xfer_from(this->queue_data, this->queue_len);
if (got_bytes == this->queue_len) {
this->queue_len = 0;
this->finish_cmd();
}
@@ -441,7 +442,8 @@ void DMAChannel::xfer_to_device() {
this->xfer_dir = DMA_DIR_TO_DEV;
if (!this->dev_obj->xfer_to(this->queue_data, this->queue_len)) {
int got_bytes = this->dev_obj->xfer_to(this->queue_data, this->queue_len);
if (got_bytes == this->queue_len) {
this->queue_len = 0;
this->finish_cmd();
}
@@ -449,6 +451,24 @@ void DMAChannel::xfer_to_device() {
this->interpret_cmd();
}
void DMAChannel::xfer_retry() {
if (this->xfer_dir == DMA_DIR_UNDEF)
return;
if (this->xfer_dir == DMA_DIR_FROM_DEV)
this->xfer_from_device();
else
this->xfer_to_device();
}
bool DMAChannel::is_ready() {
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE) ||
this->xfer_dir == DMA_DIR_UNDEF || this->cur_cmd >= DBDMA_Cmd::NOP)
return false;
return true;
}
DmaPullResult DMAChannel::pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data)
{
*avail_len = 0;
+11 -8
View File
@@ -114,14 +114,17 @@ public:
void reg_write(uint32_t offset, uint32_t value, int size);
void set_stat(uint8_t new_stat) { this->ch_stat = (this->ch_stat & 0xff00) | new_stat; }
bool is_out_active();
bool is_in_active();
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data);
int push_data(const char* src_ptr, int len);
int get_pull_data_remaining() { return this->queue_len; }
int get_push_data_remaining() { return this->queue_len; }
void end_pull_data();
void end_push_data();
bool is_out_active() override;
bool is_in_active() override;
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data) override;
int push_data(const char* src_ptr, int len) override;
int get_pull_data_remaining() override { return this->queue_len; }
int get_push_data_remaining() override { return this->queue_len; }
void end_pull_data() override;
void end_push_data() override;
bool is_ready() override;
void xfer_retry() override;
void register_dma_int(InterruptCtrl* int_ctrl_obj, uint64_t irq_id) {
this->int_ctrl = int_ctrl_obj;
+10 -7
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -96,10 +96,11 @@ public:
DmaDevice() = default;
~DmaDevice() = default;
void connect(DmaChannel *ch_obj) { this->channel_obj = ch_obj; };
void notify(DmaMsg msg) {};
virtual int xfer_from(uint8_t *buf, int len) { return len; };
virtual int xfer_to(uint8_t *buf, int len) { return len; };
virtual void connect(DmaChannel *ch_obj) { this->channel_obj = ch_obj; };
virtual void notify(DmaMsg msg) {};
virtual int xfer_from(uint8_t *buf, int len) { return len; };
virtual int xfer_to(uint8_t *buf, int len) { return len; };
virtual int tell_xfer_size() { return 0; };
protected:
DmaChannel* channel_obj = nullptr;
@@ -110,8 +111,10 @@ public:
DmaChannel() = default;
~DmaChannel() = default;
void connect(DmaDevice *dev_obj) { this->dev_obj = dev_obj; };
void notify(DmaMsg msg) {};
virtual void connect(DmaDevice *dev_obj) { this->dev_obj = dev_obj; };
virtual void notify(DmaMsg msg) {};
virtual bool is_ready() { return false; };
virtual void xfer_retry() {};
protected:
DmaDevice* dev_obj = nullptr;
+2 -2
View File
@@ -41,7 +41,7 @@ using namespace std;
static std::string hex2str(uint32_t n)
{
std::stringstream ss;
ss << setw(8) << setfill('0') << hex << n;
ss << setw(8) << right << setfill('0') << hex << n;
return ss.str();
}
@@ -591,7 +591,7 @@ void OfConfigUtils::printenv() {
ReplaceAll(val, "\r\n", "\n");
ReplaceAll(val, "\r", "\n");
ReplaceAll(val, "\n", "\n "); // 34 spaces
cout << setw(34) << left << var.first << val << endl; // name column has width 34
cout << setw(34) << left << var.first << val << right << endl; // name column has width 34
}
}
+5 -1
View File
@@ -389,6 +389,10 @@ static const PropMap PsxPci1_Properties = {
new StrProperty("")},
};
static const std::vector<std::string> Chaos_Subdevices = {
"ControlVideo"
};
static const DeviceDescription Bandit1_Descriptor = {
Bandit::create_first, {}, Bandit1_Properties
};
@@ -402,7 +406,7 @@ static const DeviceDescription PsxPci1_Descriptor = {
};
static const DeviceDescription Chaos_Descriptor = {
Chaos::create, {}, Chaos_Properties
Chaos::create, Chaos_Subdevices, Chaos_Properties
};
static const DeviceDescription AspenPci1_Descriptor = {
+2 -2
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -42,7 +42,7 @@ PCIBridgeBase::PCIBridgeBase(std::string name, PCIHeaderType hdr_type, int num_b
this->pci_wr_bridge_control = [this](uint16_t val) { this->bridge_control = val; };
};
bool PCIBridgeBase::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj)
AddressMapEntry* PCIBridgeBase::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj)
{
// FIXME: constrain region to memory range
return this->host_instance->pci_register_mmio_region(start_addr, size, obj);
+7 -7
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -43,14 +43,14 @@ public:
~PCIBridgeBase() = default;
// PCIHost methods
virtual bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj);
virtual bool pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj);
virtual AddressMapEntry* pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj) override;
virtual bool pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj) override;
// PCIBase methods
virtual uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details);
virtual uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details) override;
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details) override;
bool supports_io_space() {
bool supports_io_space() override {
return true;
};
@@ -69,7 +69,7 @@ public:
std::function<void(uint16_t)> pci_wr_bridge_control;
// HWComponent methods
virtual int device_postinit();
virtual int device_postinit() override;
protected:
// PCI configuration space state
+2 -3
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -23,7 +23,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <devices/common/pci/pcibridge.h>
#include <devices/common/pci/pcihost.h>
#include <devices/deviceregistry.h>
#include <devices/memctrl/memctrlbase.h>
#include <machines/machinefactory.h>
#include <machines/machinebase.h>
#include <endianswap.h>
@@ -90,7 +89,7 @@ void PCIHost::pci_unregister_device(int dev_fun_num)
gMachineObj->remove_device(dev_instance); // calls destructor of dev_instance since it is a unique_ptr in the device_map.
}
bool PCIHost::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj)
AddressMapEntry* PCIHost::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj)
{
MemCtrlBase *mem_ctrl = dynamic_cast<MemCtrlBase *>
(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
+4 -3
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -24,6 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <core/bitops.h>
#include <devices/common/hwinterrupt.h>
#include <devices/memctrl/memctrlbase.h>
#include <endianswap.h>
#include <cinttypes>
@@ -70,8 +71,8 @@ public:
virtual bool pci_register_device(int dev_fun_num, PCIBase* dev_instance);
virtual void pci_unregister_device(int dev_fun_num);
virtual bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj);
virtual bool pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj);
virtual AddressMapEntry* pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj);
virtual bool pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj);
virtual void attach_pci_device(const std::string& dev_name, int slot_id);
PCIBase *attach_pci_device(const std::string& dev_name, int slot_id,
+192 -91
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -72,14 +72,19 @@ void Sc53C94::reset_device()
this->data_fifo_pos = 0;
this->data_fifo[0] = 0;
this->sync_period = 5;
this->sync_offset = 0;
this->cur_step = 0;
this->seq_step = 0;
this->status = 0;
this->status &= STAT_PHASE_MASK; // reset doesn't affect bus phase bits
this->int_status = 0;
}
uint8_t Sc53C94::read(uint8_t reg_offset)
{
uint8_t status, int_status;
uint8_t bus_phase, int_flags;
switch (reg_offset) {
case Read::Reg53C94::Xfer_Cnt_LSB:
@@ -91,18 +96,25 @@ uint8_t Sc53C94::read(uint8_t reg_offset)
case Read::Reg53C94::Command:
return this->cmd_fifo[0];
case Read::Reg53C94::Status:
status = bus_obj->test_ctrl_lines(SCSI_CTRL_MSG | SCSI_CTRL_CD | SCSI_CTRL_IO);
return (this->status & 0xF8) | status;
if (this->config2 & CFG2_ENF) {
LOG_F(WARNING, "%s: phase latch not implemented", this->name.c_str());
bus_phase = SCSI_CTRL_MSG; // use reserved bus phase
} else
bus_phase = bus_obj->test_ctrl_lines(SCSI_CTRL_MSG | SCSI_CTRL_CD | SCSI_CTRL_IO);
return (this->status & 0xF8) | bus_phase;
case Read::Reg53C94::Int_Status:
int_status = this->int_status;
this->seq_step = 0;
this->int_status = 0;
int_flags = this->int_status;
if (this->irq) {
this->status &= ~(STAT_GE | STAT_PE | STAT_GCV);
this->int_status = 0;
this->seq_step = 0;
}
this->update_irq();
return int_status;
return int_flags;
case Read::Reg53C94::Seq_Step:
return this->seq_step;
case Read::Reg53C94::FIFO_Flags:
return (this->seq_step << 5) | (this->data_fifo_pos & 0x1F);
return (this->cur_step << 5) | (this->data_fifo_pos & 0x1F);
case Read::Reg53C94::Config_1:
return this->config1;
case Read::Reg53C94::Config_3:
@@ -139,6 +151,9 @@ void Sc53C94::write(uint8_t reg_offset, uint8_t value)
case Write::Reg53C94::Sel_Timeout:
this->sel_timeout = value;
break;
case Write::Reg53C94::Sync_Period:
this->sync_period = value;
break;
case Write::Reg53C94::Sync_Offset:
this->sync_offset = value;
break;
@@ -243,9 +258,9 @@ void Sc53C94::update_command_reg(uint8_t cmd)
void Sc53C94::exec_command()
{
uint8_t cmd = this->cur_cmd = this->cmd_fifo[0] & 0x7F;
uint8_t cmd = this->cur_cmd = this->cmd_fifo[0] & CMD_OPCODE;
this->is_dma_cmd = !!(this->cmd_fifo[0] & 0x80);
this->is_dma_cmd = !!(this->cmd_fifo[0] & CMD_ISDMA);
if (this->is_dma_cmd) {
if (this->config2 & CFG2_ENF) { // extended mode: 24-bit
@@ -258,6 +273,8 @@ void Sc53C94::exec_command()
}
}
this->cmd_steps = nullptr; // assume a single-step command for now
// simple commands will be executed immediately
// complex commands will be broken into multiple steps
// and handled by the sequencer
@@ -290,9 +307,10 @@ void Sc53C94::exec_command()
my_timer_id = 0;
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_RST);
});
if (!(config1 & 0x40)) {
if (!(config1 & CFG1_DISR)) {
LOG_F(INFO, "%s: reset interrupt issued", this->name.c_str());
this->int_status = INTSTAT_SRST;
this->update_irq();
}
exec_next_command();
break;
@@ -303,61 +321,86 @@ void Sc53C94::exec_command()
this->int_status = INTSTAT_ICMD;
this->update_irq();
} else {
this->seq_step = 0;
this->cmd_steps = nullptr;
this->cur_state = SeqState::XFER_BEGIN;
this->sequencer();
}
break;
case CMD_COMPLETE_STEPS:
static SeqDesc * complete_steps_desc = new SeqDesc[3]{
{(CMD_COMPLETE_STEPS << 8) + 1, SeqState::RCV_STATUS, 0, 0},
{(CMD_COMPLETE_STEPS << 8) + 2, SeqState::RCV_MESSAGE, 0, 0},
{(CMD_COMPLETE_STEPS << 8) + 3, SeqState::CMD_COMPLETE, 0, INTSTAT_SR | INTSTAT_SO}
};
if (this->bus_obj->current_phase() != ScsiPhase::STATUS) {
ABORT_F("%s: complete steps only works in the STATUS phase", this->name.c_str());
}
this->seq_step = 0;
this->cmd_steps = complete_steps_desc;
this->cur_state = this->cmd_steps->next_step;
this->cur_state = SeqState::RCV_STATUS;
this->sequencer();
break;
case CMD_MSG_ACCEPTED:
// Don't release ACK if ATN is asserted.
// Executing this command with ATN true means that
// the initiator wants to reject the current message.
// That should be recognized and handled by the target.
if (!this->bus_obj->test_ctrl_lines(SCSI_CTRL_ATN))
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_ACK);
if (this->is_initiator) {
this->bus_obj->target_next_step();
}
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_ACK);
this->int_status = INTSTAT_DIS; // TODO: handle target disconnection properly
this->int_status |= INTSTAT_SR;
this->update_irq();
exec_next_command();
break;
case CMD_XFER_PAD_BYTES:
if (this->bus_obj->current_phase() != ScsiPhase::COMMAND)
ABORT_F("%s: unsupported phase %d in CMD_XFER_PAD_BYTES",
this->name.c_str(), this->bus_obj->current_phase());
std::memset(this->data_fifo, 0, DATA_FIFO_MAX);
// FIXME: does the non-DMA version of this command use the transfer counter?
this->data_fifo_pos = std::min((int)this->set_xfer_count, DATA_FIFO_MAX);
this->cur_state = SeqState::SEND_CMD;
this->sequencer();
if (this->bus_obj->current_phase() != ScsiPhase::COMMAND) {
this->int_status |= INTSTAT_SR;
this->update_irq();
exec_next_command();
}
break;
case CMD_RESET_ATN:
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_ATN);
exec_next_command();
break;
case CMD_SELECT_NO_ATN:
static SeqDesc * sel_no_atn_desc = new SeqDesc[3]{
{(CMD_SELECT_NO_ATN << 8) + 1, SeqState::SEL_BEGIN, 0, INTSTAT_DIS },
{(CMD_SELECT_NO_ATN << 8) + 2, SeqState::SEND_CMD, 3, INTSTAT_SR | INTSTAT_SO},
{(CMD_SELECT_NO_ATN << 8) + 3, SeqState::CMD_COMPLETE, 4, INTSTAT_SR | INTSTAT_SO},
static SeqDesc * sel_no_atn_desc = new SeqDesc[2]{
{2, ScsiPhase::COMMAND, SeqState::SEND_CMD, INTSTAT_SR | INTSTAT_SO},
{4, -1, SeqState::CMD_COMPLETE, INTSTAT_SR | INTSTAT_SO},
};
this->seq_step = 0;
this->seq_step = this->cur_step = 0;
this->cmd_steps = sel_no_atn_desc;
this->cur_state = SeqState::BUS_FREE;
this->sequencer();
LOG_F(9, "%s: SELECT W/O ATN command started", this->name.c_str());
break;
case CMD_SELECT_WITH_ATN:
static SeqDesc * sel_with_atn_desc = new SeqDesc[4]{
{(CMD_SELECT_WITH_ATN << 8) + 1, SeqState::SEL_BEGIN, 0, INTSTAT_DIS },
{(CMD_SELECT_WITH_ATN << 8) + 2, SeqState::SEND_MSG, 2, INTSTAT_SR | INTSTAT_SO},
{(CMD_SELECT_WITH_ATN << 8) + 3, SeqState::SEND_CMD, 3, INTSTAT_SR | INTSTAT_SO},
{(CMD_SELECT_WITH_ATN << 8) + 4, SeqState::CMD_COMPLETE, 4, INTSTAT_SR | INTSTAT_SO},
static SeqDesc * sel_with_atn_desc = new SeqDesc[3]{
{0, ScsiPhase::MESSAGE_OUT, SeqState::SEND_MSG, INTSTAT_SR | INTSTAT_SO},
{2, ScsiPhase::COMMAND, SeqState::SEND_CMD, INTSTAT_SR | INTSTAT_SO},
{4, -1, SeqState::CMD_COMPLETE, INTSTAT_SR | INTSTAT_SO},
};
this->seq_step = 0;
this->seq_step = this->cur_step = 0;
this->bytes_out = 1; // set message length
this->cmd_steps = sel_with_atn_desc;
this->cur_state = SeqState::BUS_FREE;
this->sequencer();
LOG_F(9, "%s: SELECT WITH ATN command started", this->name.c_str());
break;
case CMD_SELECT_WITH_ATN_AND_STOP:
static SeqDesc * sel_with_atn_stop_desc = new SeqDesc[3]{
{0, ScsiPhase::MESSAGE_OUT, SeqState::SEND_MSG_EX, INTSTAT_SR | INTSTAT_SO},
{1, -1, SeqState::CMD_COMPLETE, INTSTAT_SR | INTSTAT_SO},
};
this->seq_step = this->cur_step = 0;
this->bytes_out = 1; // set message length
this->cmd_steps = sel_with_atn_stop_desc;
this->cur_state = SeqState::BUS_FREE;
this->sequencer();
LOG_F(9, "%s: SELECT WITH ATN AND STOP command started", this->name.c_str());
break;
case CMD_ENA_SEL_RESEL:
exec_next_command();
break;
@@ -380,8 +423,6 @@ void Sc53C94::exec_next_command()
}
}
constexpr auto DATA_FIFO_MAX = 16;
void Sc53C94::fifo_push(const uint8_t data)
{
if (this->data_fifo_pos < DATA_FIFO_MAX) {
@@ -410,19 +451,29 @@ uint8_t Sc53C94::fifo_pop()
void Sc53C94::seq_defer_state(uint64_t delay_ns)
{
if (seq_timer_id) {
if (this->seq_timer_id) {
TimerManager::get_instance()->cancel_timer(this->seq_timer_id);
seq_timer_id = 0;
this->seq_timer_id = 0;
}
seq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
delay_ns,
[this]() {
// re-enter the sequencer with the state specified in next_state
this->seq_timer_id = 0;
this->cur_state = this->next_state;
this->sequencer();
});
if (delay_ns) {
this->seq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
delay_ns,
[this]() {
// re-enter the sequencer with the state specified in next_state
this->seq_timer_id = 0;
this->cur_state = this->next_state;
this->sequencer();
});
} else {
this->seq_timer_id = TimerManager::get_instance()->add_immediate_timer(
[this]() {
// re-enter the sequencer with the state specified in next_state
this->seq_timer_id = 0;
this->cur_state = this->next_state;
this->sequencer();
});
}
}
void Sc53C94::sequencer()
@@ -452,7 +503,7 @@ void Sc53C94::sequencer()
break;
case SeqState::ARB_END:
if (this->bus_obj->end_arbitration(this->my_bus_id)) { // arbitration won
this->next_state = this->cmd_steps->next_step;
this->next_state = SeqState::SEL_BEGIN;
this->seq_defer_state(BUS_CLEAR_DELAY + BUS_SETTLE_DELAY);
} else { // arbitration lost
LOG_F(INFO, "%s: arbitration lost!", this->name.c_str());
@@ -473,8 +524,8 @@ void Sc53C94::sequencer()
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_SEL);
LOG_F(9, "%s: selection completed", this->name.c_str());
} else { // selection timeout
this->seq_step = this->cmd_steps->step_num;
this->int_status = this->cmd_steps->status;
this->seq_step = 0;
this->int_status = INTSTAT_DIS;
this->bus_obj->disconnect(this->my_bus_id);
this->cur_state = SeqState::IDLE;
this->update_irq();
@@ -482,29 +533,30 @@ void Sc53C94::sequencer()
}
break;
case SeqState::SEND_MSG:
case SeqState::SEND_MSG_EX:
if (this->data_fifo_pos < 1 && this->is_dma_cmd) {
if (this->drq_cb)
this->drq_cb(1);
this->int_status = INTSTAT_SR;
this->update_irq();
break;
} else {
this->bus_obj->target_xfer_data();
if (this->cur_state == SeqState::SEND_MSG_EX) {
this->notify(ScsiNotification::BUS_PHASE_CHANGE, ScsiPhase::MESSAGE_OUT);
} else {
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_ATN);
if (this->cmd_steps)
this->bus_obj->target_next_step();
}
}
this->bus_obj->target_xfer_data();
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_ATN);
break;
case SeqState::SEND_CMD:
if (this->data_fifo_pos < 1 && this->is_dma_cmd) {
if (this->drq_cb)
this->drq_cb(1);
this->int_status |= INTSTAT_SR;
this->update_irq();
break;
}
this->bus_obj->target_xfer_data();
} else
this->bus_obj->target_xfer_data();
break;
case SeqState::CMD_COMPLETE:
this->seq_step = this->cmd_steps->step_num;
this->int_status = this->cmd_steps->status;
this->int_status = INTSTAT_SR | INTSTAT_SO;
this->cur_state = SeqState::IDLE;
this->update_irq();
exec_next_command();
@@ -513,8 +565,8 @@ void Sc53C94::sequencer()
this->cur_bus_phase = this->bus_obj->current_phase();
switch (this->cur_bus_phase) {
case ScsiPhase::DATA_OUT:
if (this->is_dma_cmd) {
this->cur_state = SeqState::SEND_DATA;
if (this->is_dma_cmd && this->channel_obj->is_ready()) {
this->channel_obj->xfer_retry();
break;
}
this->bus_obj->push_data(this->target_id, this->data_fifo, this->data_fifo_pos);
@@ -523,6 +575,10 @@ void Sc53C94::sequencer()
this->sequencer();
break;
case ScsiPhase::DATA_IN:
if (this->is_dma_cmd && this->channel_obj->is_ready()) {
this->channel_obj->xfer_retry();
break;
}
this->bus_obj->negotiate_xfer(this->data_fifo_pos, this->bytes_out);
this->cur_state = SeqState::RCV_DATA;
this->rcv_data();
@@ -530,6 +586,18 @@ void Sc53C94::sequencer()
this->cur_state = SeqState::XFER_END;
this->sequencer();
}
break;
case ScsiPhase::MESSAGE_IN:
case ScsiPhase::MESSAGE_OUT:
this->cur_state = (this->cur_bus_phase == ScsiPhase::MESSAGE_OUT) ?
SeqState::SEND_MSG : SeqState::RCV_MESSAGE;
this->sequencer();
this->cur_state = SeqState::XFER_END;
this->sequencer();
break;
default:
ABORT_F("%s: unsupported phase %d in XFER_BEGIN", this->name.c_str(),
this->cur_bus_phase);
}
break;
case SeqState::XFER_END:
@@ -560,11 +628,17 @@ void Sc53C94::sequencer()
if (this->is_initiator) {
if (this->cur_state == SeqState::RCV_STATUS) {
this->bus_obj->target_next_step();
if (this->cur_bus_phase == ScsiPhase::MESSAGE_IN) {
this->bus_obj->assert_ctrl_line(this->my_bus_id, SCSI_CTRL_REQ);
this->cur_state = SeqState::RCV_MESSAGE;
this->sequencer();
}
} else if (this->cur_state == SeqState::RCV_MESSAGE) {
this->bus_obj->assert_ctrl_line(this->my_bus_id, SCSI_CTRL_ACK);
this->cmd_steps++;
this->cur_state = this->cmd_steps->next_step;
this->sequencer();
if (this->cur_cmd == CMD_COMPLETE_STEPS) {
this->cur_state = SeqState::CMD_COMPLETE;
this->sequencer();
}
}
}
break;
@@ -583,32 +657,46 @@ void Sc53C94::update_irq()
}
}
void Sc53C94::notify(ScsiMsg msg_type, int param)
void Sc53C94::notify(ScsiNotification notif_type, int param)
{
switch (msg_type) {
case ScsiMsg::CONFIRM_SEL:
switch (notif_type) {
case ScsiNotification::CONFIRM_SEL:
if (this->target_id == param) {
// cancel selection timeout timer
TimerManager::get_instance()->cancel_timer(this->seq_timer_id);
seq_timer_id = 0;
this->seq_timer_id = 0;
this->cur_state = SeqState::SEL_END;
this->sequencer();
} else {
LOG_F(WARNING, "%s: ignore invalid selection confirmation message",
LOG_F(WARNING, "%s: invalid selection confirmation message ignored",
this->name.c_str());
}
break;
case ScsiMsg::BUS_PHASE_CHANGE:
case ScsiNotification::BUS_PHASE_CHANGE:
this->cur_bus_phase = param;
if (param != ScsiPhase::BUS_FREE && this->cmd_steps != nullptr) {
this->cmd_steps++;
this->cur_state = this->cmd_steps->next_step;
this->sequencer();
if (param == ScsiPhase::BUS_FREE) { // target want to disconnect
this->int_status = INTSTAT_DIS;
this->update_irq();
this->cur_state = SeqState::IDLE;
}
if (this->cmd_steps != nullptr) {
if (this->cur_bus_phase == this->cmd_steps->expected_phase) {
this->next_state = this->cmd_steps->next_state;
this->cmd_steps++;
this->seq_defer_state(0);
} else {
this->cur_step = this->cmd_steps->step_num;
this->seq_step = this->cur_step;
this->int_status = this->cmd_steps->status;
this->update_irq();
if (this->cmd_steps->next_state == SeqState::CMD_COMPLETE)
this->exec_next_command();
}
}
break;
default:
LOG_F(9, "%s: ignore notification message, type: %d", this->name.c_str(),
msg_type);
notif_type);
}
}
@@ -628,8 +716,7 @@ int Sc53C94::send_data(uint8_t* dst_ptr, int count)
if (this->data_fifo_pos > 0) {
std::memmove(this->data_fifo, &this->data_fifo[actual_count], this->data_fifo_pos);
} else if (this->cur_bus_phase == ScsiPhase::DATA_OUT) {
this->cmd_steps++;
this->cur_state = this->cmd_steps->next_step;
ABORT_F("%s: don't know what to do next!", this->name.c_str());
this->sequencer();
}
@@ -752,38 +839,51 @@ void Sc53C94::dma_stop()
}
int Sc53C94::xfer_from(uint8_t *buf, int len) {
if (len > this->xfer_count + this->data_fifo_pos)
LOG_F(WARNING, "%s: DMA xfer len > command xfer len", this->name.c_str());
int bytes_moved = 0;
if (this->cur_cmd != CMD_XFER || !this->is_dma_cmd ||
this->cur_bus_phase != ScsiPhase::DATA_IN) {
LOG_F(9, "%s: ignoring DMA data transfer request", this->name.c_str());
return bytes_moved;
}
len = std::min(len, (int)(this->xfer_count));
if (this->data_fifo_pos) {
int fifo_bytes = std::min(this->data_fifo_pos, len);
std::memcpy(buf, this->data_fifo, fifo_bytes);
this->data_fifo_pos -= fifo_bytes;
this->xfer_count -= fifo_bytes;
len -= fifo_bytes;
bytes_moved += fifo_bytes;
buf += fifo_bytes;
if (!this->xfer_count) {
this->status |= STAT_TC; // signal zero transfer count
this->cur_state = SeqState::XFER_END;
this->sequencer();
return 0;
return bytes_moved;
}
}
if (this->bus_obj->pull_data(this->target_id, buf, this->xfer_count)) {
bytes_moved += this->xfer_count;
this->xfer_count = 0;
this->status |= STAT_TC; // signal zero transfer count
this->cur_state = SeqState::XFER_END;
this->sequencer();
return 0;
}
return len;
return bytes_moved;
}
int Sc53C94::xfer_to(uint8_t *buf, int len) {
if (!this->xfer_count)
return len;
int bytes_moved = 0;
if (!this->xfer_count || !this->is_dma_cmd) {
LOG_F(9, "%s: ignoring DMA data transfer request", this->name.c_str());
return bytes_moved;
}
len = std::min(len, (int)(this->xfer_count));
// Being in the DATA_OUT phase means that we're about to move
// a big chunk of data. The real device uses its FIFO as buffer.
@@ -792,6 +892,7 @@ int Sc53C94::xfer_to(uint8_t *buf, int len) {
if (this->cur_bus_phase == ScsiPhase::DATA_OUT) {
if (this->bus_obj->push_data(this->target_id, buf, len)) {
this->xfer_count -= len;
bytes_moved += len;
if (!this->xfer_count) {
this->status |= STAT_TC; // signal zero transfer count
this->cur_state = SeqState::XFER_END;
@@ -806,16 +907,16 @@ int Sc53C94::xfer_to(uint8_t *buf, int len) {
// fill in the data FIFO first
uint32_t fifo_bytes = std::min(len, DATA_FIFO_MAX - this->data_fifo_pos);
std::memcpy(&this->data_fifo[this->data_fifo_pos], buf, fifo_bytes);
len -= fifo_bytes;
this->data_fifo_pos += fifo_bytes;
this->xfer_count -= fifo_bytes;
bytes_moved += fifo_bytes;
if (!this->xfer_count) {
this->status |= STAT_TC; // signal zero transfer count
this->sequencer();
}
}
return len;
return bytes_moved;
}
static const PropMap Sc53C94_properties = {
+37 -25
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -94,9 +94,9 @@ enum {
CMD_XFER = 0x10,
CMD_COMPLETE_STEPS = 0x11,
CMD_MSG_ACCEPTED = 0x12,
//CMD_TRANSFER_PAD_BYTES = 0x18,
CMD_XFER_PAD_BYTES = 0x18,
CMD_SET_ATN = 0x1A, // no interrupt
//CMD_RESET_ATN = 0x1B, // no interrupt
CMD_RESET_ATN = 0x1B, // no interrupt
// Target commands
//CMD_SEND_MESSAGE = 0x20,
@@ -111,13 +111,13 @@ enum {
//CMD_RECEIVE_DATA = 0x2A,
//CMD_RECEIVE_COMMAND_STEPS = 0x2B,
CMD_DMA_STOP = 0x04, // no interrupt
CMD_ACCESS_FIFO_COMMAND = 0x05,
//CMD_ACCESS_FIFO_COMMAND = 0x05,
// Idle Commands
//CMD_RESELECT_STEPS = 0x40,
CMD_SELECT_NO_ATN = 0x41,
CMD_SELECT_WITH_ATN = 0x42,
//CMD_SELECT_WITH_ATN_AND_STOP = 0x43,
CMD_SELECT_WITH_ATN_AND_STOP = 0x43,
CMD_ENA_SEL_RESEL = 0x44, // no interrupt
//CMD_DISABLE_SEL_RESEL = 0x45,
//CMD_SELECT_WITH_ATN3_STEPS = 0x46,
@@ -128,14 +128,12 @@ enum {
CMD_ISDMA = 0x80,
};
/** Status register bits. **/
/** Status register bits. */
enum {
//SCSI_CTRL_IO = 0x01, // Input/Output
//SCSI_CTRL_CD = 0x02, // Command/Data
//SCSI_CTRL_MSG = 0x04, // Message
//STAT_GCV = 0x08, // Group Code Valid
STAT_PHASE_MASK = 0x07, // mask for I/O, Command and Message bits
STAT_GCV = 0x08, // Group Code Valid
STAT_TC = 0x10, // Terminal count (NCR) / count to zero (AMD)
//STAT_PE = 0x20, // Parity Error
STAT_PE = 0x20, // Parity Error
STAT_GE = 0x40, // Gross Error (NCR) / Illegal Operation Error (AMD)
STAT_INT = 0x80, // Interrupt
};
@@ -152,6 +150,12 @@ enum {
INTSTAT_SEL = 0x01, // selected as a target without attention
};
/** Configuration register 1 bits. */
enum {
CFG1_DISR = 0x40, // disable interrupt on SCSI reset
};
/** Configuration register 2 bits. */
enum {
CFG2_ENF = 0x40, // Am53CF94: enable features (ENF) bit
};
@@ -166,6 +170,7 @@ namespace SeqState {
SEL_BEGIN,
SEL_END,
SEND_MSG,
SEND_MSG_EX,
SEND_CMD,
CMD_COMPLETE,
XFER_BEGIN,
@@ -177,11 +182,13 @@ namespace SeqState {
};
};
/** Sequence descriptor for sequencer commands. */
constexpr auto DATA_FIFO_MAX = 16;
/** Sequence descriptor for multistep commands. */
typedef struct {
int seq_id;
int next_step;
int step_num;
int expected_phase;
int next_state;
int status;
} SeqDesc;
@@ -197,7 +204,7 @@ public:
}
// HWComponent methods
int device_postinit();
int device_postinit() override;
// 53C94 registers access
uint8_t read(uint8_t reg_offset);
@@ -228,16 +235,19 @@ public:
}
// ScsiDevice methods
void notify(ScsiMsg msg_type, int param);
bool prepare_data() { return false; };
bool get_more_data() { return false; };
bool has_data() { return this->data_fifo_pos != 0; };
int send_data(uint8_t* dst_ptr, int count);
void process_command() {};
void notify(ScsiNotification notif_type, int param) override;
bool prepare_data() override { return false; };
bool get_more_data() override { return false; };
bool has_data() override { return this->data_fifo_pos != 0; };
int send_data(uint8_t* dst_ptr, int count) override;
void process_command() override {};
// DmaChannel methods
int xfer_from(uint8_t *buf, int len); // Must be marked override!
int xfer_to(uint8_t *buf, int len); // Must be marked override!
// DmaDevice methods
int xfer_from(uint8_t *buf, int len) override;
int xfer_to(uint8_t *buf, int len) override;
int tell_xfer_size() override {
return this->xfer_count;
};
protected:
void reset_device();
@@ -260,7 +270,7 @@ private:
uint32_t my_timer_id = 0;
uint8_t cmd_fifo[2];
uint8_t data_fifo[16];
uint8_t data_fifo[DATA_FIFO_MAX];
int cmd_fifo_pos = 0;
int data_fifo_pos = 0;
int bytes_out = 0;
@@ -272,6 +282,7 @@ private:
uint8_t int_status = 0;
uint8_t seq_step = 0;
uint8_t sel_timeout = 0;
uint8_t sync_period = 5;
uint8_t sync_offset = 0;
uint8_t clk_factor = 0;
uint8_t config1 = 0;
@@ -287,6 +298,7 @@ private:
uint8_t cur_cmd = 0;
bool is_dma_cmd = false;
int cur_bus_phase = 0;
uint8_t cur_step = 0; // internal step counter for multistep commands
// interrupt related stuff
InterruptCtrl* int_ctrl = nullptr;
+20 -7
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -47,6 +47,7 @@ enum {
SCSI_CTRL_RST = 1 << 15,
};
/** SCSI bus phases. */
namespace ScsiPhase {
enum : int {
BUS_FREE = 0,
@@ -63,6 +64,7 @@ namespace ScsiPhase {
};
};
/** SCSI status codes. */
namespace ScsiStatus {
enum : uint8_t {
GOOD = 0,
@@ -70,6 +72,7 @@ namespace ScsiStatus {
};
};
/** Standard message codes. */
namespace ScsiMessage {
enum : uint8_t {
COMMAND_COMPLETE = 0,
@@ -82,13 +85,19 @@ namespace ScsiMessage {
};
};
enum ScsiMsg : int {
/** Extended message codes. */
namespace ScsiExtMessage {
enum : uint8_t {
MODIFY_DATA_PTR = 0,
SYNCH_XFER_REQ = 1,
WIDE_XFER_REQ = 3,
};
};
/** Internal notification codes for our SCSI implementation. */
enum ScsiNotification : int {
CONFIRM_SEL = 1,
BUS_PHASE_CHANGE,
SEND_CMD_BEGIN,
SEND_CMD_END,
MESSAGE_BEGIN,
MESSAGE_END,
};
enum ScsiCommand : uint8_t {
@@ -180,10 +189,11 @@ public:
};
~ScsiDevice() = default;
virtual void notify(ScsiMsg msg_type, int param);
virtual void notify(ScsiNotification notif_type, int param);
virtual void next_step();
virtual void prepare_xfer(ScsiBus* bus_obj, int& bytes_in, int& bytes_out);
virtual void switch_phase(const int new_phase);
virtual bool allow_phase_change();
virtual bool has_data() { return this->data_size != 0; };
virtual int xfer_data();
@@ -195,6 +205,7 @@ public:
virtual bool prepare_data() = 0;
virtual bool get_more_data() = 0;
virtual void process_command() = 0;
virtual void process_message();
void set_bus_object_ptr(ScsiBus *bus_obj_ptr) {
this->bus_obj = bus_obj_ptr;
@@ -224,6 +235,8 @@ protected:
uint8_t last_selection_message = 0;
ScsiBus* bus_obj;
int *seq_steps = nullptr;
action_callback pre_xfer_action = nullptr;
action_callback post_xfer_action = nullptr;
};
+2 -2
View File
@@ -66,7 +66,7 @@ void ScsiBus::change_bus_phase(int initiator_id)
if (i == initiator_id)
continue; // don't notify the initiator
if (this->devices[i] != nullptr) {
this->devices[i]->notify(ScsiMsg::BUS_PHASE_CHANGE, this->cur_phase);
this->devices[i]->notify(ScsiNotification::BUS_PHASE_CHANGE, this->cur_phase);
}
}
}
@@ -242,7 +242,7 @@ void ScsiBus::confirm_selection(int target_id)
// notify initiator about selection confirmation from target
if (this->initiator_id >= 0) {
this->devices[this->initiator_id]->notify(ScsiMsg::CONFIRM_SEL, target_id);
this->devices[this->initiator_id]->notify(ScsiNotification::CONFIRM_SEL, target_id);
}
}
+5 -5
View File
@@ -160,9 +160,9 @@ void ScsiBusController::sequencer() {
}
}
void ScsiBusController::notify(ScsiMsg msg_type, int param) {
switch (msg_type) {
case ScsiMsg::CONFIRM_SEL:
void ScsiBusController::notify(ScsiNotification notif_type, int param) {
switch (notif_type) {
case ScsiNotification::CONFIRM_SEL:
if (this->dst_id == param) {
// cancel selection timeout timer
TimerManager::get_instance()->cancel_timer(this->seq_timer_id);
@@ -174,7 +174,7 @@ void ScsiBusController::notify(ScsiMsg msg_type, int param) {
this->name.c_str());
}
break;
case ScsiMsg::BUS_PHASE_CHANGE:
case ScsiNotification::BUS_PHASE_CHANGE:
this->cur_bus_phase = param;
#if 0
if (param != ScsiPhase::BUS_FREE && this->cmd_steps != nullptr) {
@@ -186,7 +186,7 @@ void ScsiBusController::notify(ScsiMsg msg_type, int param) {
break;
default:
LOG_F(9, "%s: ignore notification message, type: %d", this->name.c_str(),
msg_type);
notif_type);
}
}
+8 -8
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -74,16 +74,16 @@ public:
virtual void report_error(const int error) = 0;
// ScsiDevice methods
void notify(ScsiMsg msg_type, int param);
bool prepare_data() { return false; };
bool get_more_data() { return false; };
bool has_data() { return false; };
void notify(ScsiNotification notif_type, int param) override;
bool prepare_data() override { return false; };
bool get_more_data() override { return false; };
bool has_data() override { return false; };
bool rcv_data();
int send_data(uint8_t* dst_ptr, int count);
void process_command() {};
int send_data(uint8_t* dst_ptr, int count) override;
void process_command() override {};
// DmaDevice methods
int xfer_from(uint8_t *buf, int len); // must be marked OVERRIDE!
int xfer_from(uint8_t *buf, int len) override;
protected:
void seq_defer_state(uint64_t delay_ns);
+28 -28
View File
@@ -65,7 +65,9 @@ void ScsiCdrom::process_command()
this->read(lba, cmd[4], 6);
break;
case ScsiCommand::INQUIRY:
this->inquiry();
this->bytes_out = this->inquiry(cmd, this->data_buf);
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
this->switch_phase(ScsiPhase::DATA_IN);
break;
case ScsiCommand::MODE_SELECT_6:
this->mode_select_6(cmd[4]);
@@ -151,55 +153,53 @@ int ScsiCdrom::test_unit_ready()
return ScsiError::NO_ERROR;
}
void ScsiCdrom::inquiry() {
int page_num = cmd_buf[2];
int alloc_len = cmd_buf[4];
uint32_t ScsiCdrom::inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr) {
int page_num = cmd_ptr[2];
int alloc_len = cmd_ptr[4];
if (page_num) {
ABORT_F("%s: invalid page number in INQUIRY", this->name.c_str());
}
if (alloc_len > 36) {
LOG_F(ERROR, "%s: more than 36 bytes requested in INQUIRY", this->name.c_str());
LOG_F(WARNING, "%s: more than 36 bytes requested in INQUIRY", this->name.c_str());
}
int lun;
if (this->last_selection_has_atention) {
LOG_F(9, "%s: INQUIRY (%d bytes) with ATN LUN = %02x & 7", this->name.c_str(),
alloc_len, this->last_selection_message);
LOG_F(INFO, "%s: INQUIRY (%d bytes) with ATN LUN = %02x & 7", this->name.c_str(),
alloc_len, this->last_selection_message);
lun = this->last_selection_message & 7;
}
else {
LOG_F(9, "%s: INQUIRY (%d bytes) with NO ATN LUN = %02x >> 5", this->name.c_str(),
alloc_len, cmd_buf[1]);
lun = cmd_buf[1] >> 5;
LOG_F(INFO, "%s: INQUIRY (%d bytes) with NO ATN LUN = %02x >> 5", this->name.c_str(),
alloc_len, cmd_ptr[1]);
lun = cmd_ptr[1] >> 5;
}
this->data_buf[0] = (lun == this->lun) ? 5 : 0x7f; // device type: CD-ROM
this->data_buf[1] = 0x80; // removable media
this->data_buf[2] = 2; // ANSI version: SCSI-2
this->data_buf[3] = 1; // response data format
this->data_buf[4] = 0x1F; // additional length
this->data_buf[5] = 0;
this->data_buf[6] = 0;
this->data_buf[7] = 0x18; // supports synchronous xfers and linked commands
std::memcpy(&this->data_buf[8], vendor_info, 8);
std::memcpy(&this->data_buf[16], prod_info, 16);
std::memcpy(&this->data_buf[32], rev_info, 4);
//std::memcpy(&this->data_buf[36], serial_number, 8);
data_ptr[0] = (lun == this->lun) ? 5 : 0x7f; // device type: CD-ROM
data_ptr[1] = 0x80; // removable media
data_ptr[2] = 2; // ANSI version: SCSI-2
data_ptr[3] = 1; // response data format
data_ptr[4] = 0x1F; // additional length
data_ptr[5] = 0;
data_ptr[6] = 0;
data_ptr[7] = 0x18; // supports synchronous xfers and linked commands
std::memcpy(&data_ptr[8], vendor_info, 8);
std::memcpy(&data_ptr[16], prod_info, 16);
std::memcpy(&data_ptr[32], rev_info, 4);
//std::memcpy(&data_ptr[36], serial_number, 8);
//etc.
if (alloc_len < 36) {
LOG_F(ERROR, "Inappropriate Allocation Length: %d", alloc_len);
LOG_F(ERROR, "%s: allocation length too small: %d", this->name.c_str(),
alloc_len);
}
else {
memset(&this->data_buf[36], 0, alloc_len - 36);
memset(&data_ptr[36], 0, alloc_len - 36);
}
this->bytes_out = alloc_len;
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
this->switch_phase(ScsiPhase::DATA_IN);
return alloc_len;
}
static char Apple_Copyright_Page_Data[] = "APPLE COMPUTER, INC ";
+1 -1
View File
@@ -44,7 +44,7 @@ public:
protected:
int test_unit_ready();
void read(uint32_t lba, uint16_t nblocks, uint8_t cmd_len);
void inquiry();
uint32_t inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr) override;
void mode_select_6(uint8_t param_len);
void mode_sense_6();
+66 -13
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -26,9 +26,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes>
#include <cstring>
void ScsiDevice::notify(ScsiMsg msg_type, int param)
void ScsiDevice::notify(ScsiNotification notif_type, int param)
{
if (msg_type == ScsiMsg::BUS_PHASE_CHANGE) {
if (notif_type == ScsiNotification::BUS_PHASE_CHANGE) {
switch (param) {
case ScsiPhase::RESET:
LOG_F(9, "ScsiDevice %d: bus reset aknowledged", this->scsi_id);
@@ -45,12 +45,11 @@ void ScsiDevice::notify(ScsiMsg msg_type, int param)
return;
this->bus_obj->assert_ctrl_line(this->scsi_id, SCSI_CTRL_BSY);
this->bus_obj->confirm_selection(this->scsi_id);
this->seq_steps = nullptr;
this->initiator_id = this->bus_obj->get_initiator_id();
if (this->bus_obj->test_ctrl_lines(SCSI_CTRL_ATN)) {
this->switch_phase(ScsiPhase::MESSAGE_OUT);
this->last_selection_has_atention = true;
this->last_selection_message = this->msg_buf[0];
//LOG_F(SCSIDEVICE, "%s: received message:0x%02x", this->get_name().c_str(), this->msg_buf[0]);
this->switch_phase(ScsiPhase::MESSAGE_OUT);
} else {
this->last_selection_has_atention = false;
this->switch_phase(ScsiPhase::COMMAND);
@@ -68,8 +67,36 @@ void ScsiDevice::switch_phase(const int new_phase)
this->bus_obj->switch_phase(this->scsi_id, this->cur_phase);
}
bool ScsiDevice::allow_phase_change() {
if (this->bus_obj->test_ctrl_lines(SCSI_CTRL_ATN | SCSI_CTRL_ACK) ==
(SCSI_CTRL_ATN | SCSI_CTRL_ACK))
ABORT_F("%s: reject message requested", this->name.c_str());
if (this->data_size || this->bus_obj->test_ctrl_lines(SCSI_CTRL_ACK))
return false;
else
return true;
}
void ScsiDevice::next_step()
{
// special case: data transfers during MESSAGE_IN phase
// require handshaking. Rejecting needs to be detected too.
if (bus_obj->current_phase() == ScsiPhase::MESSAGE_IN &&
!this->allow_phase_change())
return;
// check for puggable sequences and follow them if applicable
if (this->seq_steps && *this->seq_steps >= 0) {
if (this->cur_phase == *this->seq_steps) {
this->seq_steps++;
if (*this->seq_steps >= 0) {
this->switch_phase(*this->seq_steps);
return;
}
}
}
switch (this->cur_phase) {
case ScsiPhase::DATA_OUT:
if (this->data_size >= this->incoming_size) {
@@ -96,6 +123,8 @@ void ScsiDevice::next_step()
break;
case ScsiPhase::STATUS:
this->bus_obj->release_ctrl_line(this->scsi_id, SCSI_CTRL_REQ);
this->data_ptr = this->msg_buf;
this->data_size = 1;
this->switch_phase(ScsiPhase::MESSAGE_IN);
break;
case ScsiPhase::MESSAGE_OUT:
@@ -104,6 +133,7 @@ void ScsiDevice::next_step()
case ScsiPhase::MESSAGE_IN:
case ScsiPhase::BUS_FREE:
this->bus_obj->release_ctrl_lines(this->scsi_id);
this->seq_steps = nullptr;
this->switch_phase(ScsiPhase::BUS_FREE);
break;
default:
@@ -137,9 +167,6 @@ void ScsiDevice::prepare_xfer(ScsiBus* bus_obj, int& bytes_in, int& bytes_out)
bytes_out = 0;
break;
case ScsiPhase::MESSAGE_IN:
this->data_ptr = this->msg_buf;
this->data_size = 1;
bytes_out = 1;
break;
default:
ABORT_F("ScsiDevice: unhandled phase %d in prepare_xfer()", this->cur_phase);
@@ -154,14 +181,14 @@ int ScsiDevice::xfer_data() {
switch (this->cur_phase) {
case ScsiPhase::MESSAGE_OUT:
if (this->bus_obj->pull_data(this->initiator_id, this->msg_buf, 1)) {
if (this->msg_buf[0] & 0x80) {
if (this->msg_buf[0] & ScsiMessage::IDENTIFY) {
LOG_F(9, "%s: IDENTIFY MESSAGE received, code = 0x%X",
this->name.c_str(), this->msg_buf[0]);
this->next_step();
} else {
ABORT_F("%s: unsupported message received, code = 0x%X",
this->name.c_str(), this->msg_buf[0]);
this->process_message();
}
if (this->last_selection_has_atention)
this->last_selection_message = this->msg_buf[0];
}
break;
case ScsiPhase::COMMAND:
@@ -256,3 +283,29 @@ void ScsiDevice::report_error(uint8_t sense_key, uint8_t asc) {
this->sksv = 0xC0; // sksv=1, C/D=Command, BPV=0, BP=0
this->switch_phase(ScsiPhase::STATUS);
}
void ScsiDevice::process_message() {
static int sdtr_response_seq[4] = {ScsiPhase::MESSAGE_OUT, ScsiPhase::MESSAGE_IN,
ScsiPhase::COMMAND, -1};
if (this->msg_buf[0] == 1) { // extended messages
if (!this->bus_obj->pull_data(this->initiator_id, &this->msg_buf[1], 1) ||
!this->bus_obj->pull_data(this->initiator_id, &this->msg_buf[2], this->msg_buf[1]))
ABORT_F("%s: incomplete message received", this->name.c_str());
switch(this->msg_buf[2]) {
case ScsiExtMessage::SYNCH_XFER_REQ:
LOG_F(INFO, "%s: SDTR message received", this->name.c_str());
// confirm synchronous transfer capability by sending back the SDTR message
this->seq_steps = sdtr_response_seq;
this->data_ptr = this->msg_buf;
this->data_size = 5;
break;
default:
LOG_F(ERROR, "%s: unsupported message %d", this->name.c_str(), this->msg_buf[2]);
}
} else if ((this->msg_buf[0] >> 4) == 2) { // two-byte messages
if (!this->bus_obj->pull_data(this->initiator_id, &this->msg_buf[1], 1))
ABORT_F("%s: incomplete message received", this->name.c_str());
}
}
+27 -36
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -84,7 +84,8 @@ void ScsiHardDisk::process_command() {
this->write(lba, cmd[4], 6);
break;
case ScsiCommand::INQUIRY:
this->inquiry();
this->bytes_out = this->inquiry(cmd, this->data_buf);
this->switch_phase(ScsiPhase::DATA_IN);
break;
case ScsiCommand::MODE_SELECT_6:
mode_select_6(cmd[4]);
@@ -92,6 +93,9 @@ void ScsiHardDisk::process_command() {
case ScsiCommand::MODE_SENSE_6:
this->mode_sense_6();
break;
case ScsiCommand::START_STOP_UNIT:
this->switch_phase(ScsiPhase::STATUS);
break;
case ScsiCommand::PREVENT_ALLOW_MEDIUM_REMOVAL:
this->eject_allowed = (cmd[4] & 1) == 0;
this->switch_phase(ScsiPhase::STATUS);
@@ -212,16 +216,16 @@ int ScsiHardDisk::req_sense(uint16_t alloc_len) {
return ScsiError::NO_ERROR;
}
void ScsiHardDisk::inquiry() {
int page_num = cmd_buf[2];
int alloc_len = cmd_buf[4];
uint32_t ScsiHardDisk::inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr) {
int page_num = cmd_ptr[2];
int alloc_len = cmd_ptr[4];
if (page_num) {
ABORT_F("%s: invalid page number in INQUIRY", this->name.c_str());
}
if (alloc_len > 36) {
LOG_F(INFO, "%s: %d bytes requested in INQUIRY", this->name.c_str(), alloc_len);
LOG_F(WARNING, "%s: more than 36 bytes requested in INQUIRY", this->name.c_str());
}
int lun;
@@ -231,22 +235,23 @@ void ScsiHardDisk::inquiry() {
lun = this->last_selection_message & 7;
}
else {
LOG_F(INFO, "%s: INQUIRY (%d bytes) with NO ATN LUN = %02x >> 5", this->name.c_str(), alloc_len, cmd_buf[1]);
lun = cmd_buf[1] >> 5;
LOG_F(INFO, "%s: INQUIRY (%d bytes) with NO ATN LUN = %02x >> 5", this->name.c_str(),
alloc_len, cmd_ptr[1]);
lun = cmd_ptr[1] >> 5;
}
this->data_buf[0] = (lun == this->lun) ? 0 : 0x7f; // device type: Direct-access block device (hard drive)
this->data_buf[1] = 0; // non-removable media; 0x80 = removable media
this->data_buf[2] = 2; // ANSI version: SCSI-2
this->data_buf[3] = 1; // response data format
this->data_buf[4] = 0x1F; // additional length
this->data_buf[5] = 0;
this->data_buf[6] = 0;
this->data_buf[7] = 0x18; // supports synchronous xfers and linked commands
std::memcpy(&this->data_buf[8], vendor_info, 8);
std::memcpy(&this->data_buf[16], prod_info, 16);
std::memcpy(&this->data_buf[32], rev_info, 4);
//std::memcpy(&this->data_buf[36], serial_number, 8);
data_ptr[0] = (lun == this->lun) ? 0 : 0x7f; // device type: Direct-access block device (hard drive)
data_ptr[1] = 0; // non-removable media; 0x80 = removable media
data_ptr[2] = 2; // ANSI version: SCSI-2
data_ptr[3] = 1; // response data format
data_ptr[4] = 0x1F; // additional length
data_ptr[5] = 0;
data_ptr[6] = 0;
data_ptr[7] = 0x18; // supports synchronous xfers and linked commands
std::memcpy(&data_ptr[8], vendor_info, 8);
std::memcpy(&data_ptr[16], prod_info, 16);
std::memcpy(&data_ptr[32], rev_info, 4);
//std::memcpy(&data_ptr[36], serial_number, 8);
//etc.
if (alloc_len < 36) {
@@ -254,12 +259,10 @@ void ScsiHardDisk::inquiry() {
alloc_len);
}
else {
memset(&this->data_buf[36], 0, alloc_len - 36);
memset(&data_ptr[36], 0, alloc_len - 36);
}
this->bytes_out = alloc_len;
this->switch_phase(ScsiPhase::DATA_IN);
return alloc_len;
}
int ScsiHardDisk::send_diagnostic() {
@@ -303,18 +306,6 @@ void ScsiHardDisk::mode_sense_6() {
return;
}
if (page_ctrl == 2) {
LOG_F(ERROR, "%s: page_ctrl 2 DEFAULT VALUES is not implemented", this->name.c_str());
this->status = ScsiStatus::CHECK_CONDITION;
this->sense = ScsiSense::ILLEGAL_REQ;
this->asc = ScsiError::INVALID_CDB;
this->ascq = 0;
this->sksv = 0xC0; // sksv=1, C/D=Command, BPV=0, BP=0
this->field = 2;
this->switch_phase(ScsiPhase::STATUS);
return;
}
if (page_ctrl == 3) {
LOG_F(INFO, "%s: page_ctrl 3 SAVED VALUES is not implemented", this->name.c_str());
this->status = ScsiStatus::CHECK_CONDITION;
+1 -1
View File
@@ -49,7 +49,7 @@ protected:
void mode_sense_6();
void format();
void inquiry();
uint32_t inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr);
void read_capacity_10();
void read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len);
void write(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len);
+2
View File
@@ -146,6 +146,8 @@ enum {
constexpr auto CUDA_IN_BUF_SIZE = 256;
/** PRAM addresses within Cuda's internal memory. */
// = 0xA1; // byte, read/write 0x00 (Power Mac 6100)
// = 0xB3; // 2 bytes, write 0x3020 (Power Mac 6100)
constexpr auto CUDA_PRAM_START = 0x100; // starting address of PRAM
constexpr auto CUDA_PRAM_END = 0x1FF; // last byte of PRAM
constexpr auto CUDA_ROM_START = 0xF00; // starting address of ROM containing Cuda FW
+26 -1
View File
@@ -41,21 +41,41 @@ enum BigMacReg : uint16_t {
TX_FIFO_CSR = 0x100,
TX_FIFO_TH = 0x110,
RX_FIFO_CSR = 0x120,
MEM_ADD = 0x130, // Memory Address
MEM_DATA_HI = 0x140, // Memory Data High
MEM_DATA_LO = 0x150, // Memory Data Low
XCVR_IF = 0x160, // Transceiver IF Control
CHIP_ID = 0x170,
MIF_CSR = 0x180,
SROM_CSR = 0x190,
TX_PNTR = 0x1A0, // Apple: TX Pointer
RX_PNTR = 0x1B0, // Apple: RX Pointer
GLOB_STAT = 0x200, // Apple: kSTAT, Sun: Global Status Register
EVENT_MASK = 0x210, // ambiguously called INT_DISABLE in the Apple source
SROM_CSR = 0x190,
TX_SW_RST = 0x420,
TX_CONFIG = 0x430,
IPG_1 = 0x440, // Inter Packet Gap 1
IPG_2 = 0x450,
A_LIMIT = 0x460, // Attempt Limit
SLOT = 0x470,
PA_LEN = 0x480, // Apple: PA Len, Sun: PA Size
PA_PAT = 0x490,
TX_SFD = 0x4A0,
JAM_SIZE = 0x4B0,
TX_MAX = 0x4C0, // Max frame size
TX_MIN = 0x4D0, // Min frame size
PEAK_ATT = 0x4E0, // Apple: kPAREG, Sun: PeakAttempts Register
DEFER_TMR = 0x4F0, // Also called DCNT by Apple
NC_CNT = 0x500, // Normal Collision Counter
NT_CNT = 0x510, // Apple: Network Collision Counter
EX_CNT = 0x520, // Excessive Collision Counter
LT_CNT = 0x530, // Late Collision Counter
RNG_SEED = 0x540,
TX_SM = 0x550,
RX_SW_RST = 0x620,
RX_CONFIG = 0x630,
RX_MAX = 0x640,
RX_MIN = 0x650,
MAC_ADDR_2 = 0x660,
MAC_ADDR_1 = 0x670,
MAC_ADDR_0 = 0x680,
@@ -63,11 +83,16 @@ enum BigMacReg : uint16_t {
RX_LE_CNT = 0x6A0, // Length Error Counter
RX_AE_CNT = 0x6B0, // Alignment Error Counter
RX_FE_CNT = 0x6C0, // FCS Error Counter
RX_ST_MCHN = 0x6D0, // RX State Machine
RX_CVE_CNT = 0x6E0, // Code Violation Error Counter
HASH_TAB_3 = 0x700,
HASH_TAB_2 = 0x710,
HASH_TAB_1 = 0x720,
HASH_TAB_0 = 0x730,
AFR_2 = 0x740, // Address Filter 2
AFR_1 = 0x750, // Address Filter 1
AFR_0 = 0x760, // Address Filter 0
AFC_R = 0x770, // Address Filter Mask
};
/* MIF_CSR bit definitions. */
+1 -1
View File
@@ -400,7 +400,7 @@ void Swim3Ctrl::init_timer(const uint8_t start_val)
this->one_us_timer_start = TimerManager::get_instance()->current_time_ns();
this->one_us_timer_id = TimerManager::get_instance()->add_oneshot_timer(
this->timer_val * NS_PER_USEC,
uint32_t(this->timer_val) * NS_PER_USEC,
[this]() {
this->timer_val = 0;
this->int_flags |= INT_TIMER_DONE;
+69 -24
View File
@@ -54,7 +54,8 @@ AMIC::AMIC() : MMIODevice()
// connect internal SCSI controller
this->scsi = dynamic_cast<Sc53C94*>(gMachineObj->get_comp_by_name("Sc53C94"));
this->curio_dma = std::unique_ptr<AmicScsiDma> (new AmicScsiDma());
this->scsi->set_dma_channel(this->curio_dma.get());
this->curio_dma->connect(this->scsi);
this->scsi->connect(this->curio_dma.get());
this->scsi->set_drq_callback([this](const uint8_t drq_state) {
if (drq_state & 1)
via2_ifr |= VIA2_INT_SCSI_DRQ;
@@ -124,8 +125,6 @@ int AMIC::device_postinit()
uint32_t AMIC::read(uint32_t rgn_start, uint32_t offset, int size)
{
uint32_t phase_val;
// subdevices registers
switch(offset >> 12) {
case 0: // VIA1 registers
@@ -157,14 +156,15 @@ uint32_t AMIC::read(uint32_t rgn_start, uint32_t offset, int size)
return (this->awacs->read_stat() >> (offset & 3) * 8) & 0xFF;
case AMICReg::Snd_Phase0:
case AMICReg::Snd_Phase1:
case AMICReg::Snd_Phase2:
case AMICReg::Snd_Phase2: {
// the sound phase register is organized as follows:
// 000000oo oooooooo oopppppp where 'o' is the 12-bit offset
// into the DMA buffer and 'p' is an undocumented prescale value
// HWInit doesn't care about. Let's hope it will be sufficient
// to return 0 for prescale.
phase_val = this->snd_out_dma->get_cur_buf_pos() << 6;
uint32_t phase_val = this->snd_out_dma->get_cur_buf_pos() << 6;
return (phase_val >> ((2 - (offset & 3)) * 8)) & 0xFF;
}
case AMICReg::Snd_Out_Ctrl:
return this->snd_out_ctrl;
case AMICReg::Snd_Out_DMA:
@@ -217,8 +217,28 @@ uint32_t AMIC::read(uint32_t rgn_start, uint32_t offset, int size)
return this->floppy_dma->read_stat();
case SCC_DMA_Xmt_A_Ctrl:
return this->escc_xmit_a_dma->read_stat();
case SCC_RXA_Byte_Cnt_Hi:
return 0;
case SCC_RXA_Byte_Cnt_Lo:
return 0;
case SCC_DMA_Rcv_A_Ctrl: {
uint32_t value = std::rand() & (-1U >> (32 - size * 8));
LOG_F(WARNING, "AMIC SCC Receive Ch A DMA Ctrl read @%x.%c = %0*x", offset,
SIZE_ARG(size), size * 2, value);
return value;
}
case SCC_DMA_Xmt_B_Ctrl:
return this->escc_xmit_b_dma->read_stat();
case SCC_RXB_Byte_Cnt_Hi:
return 0;
case SCC_RXB_Byte_Cnt_Lo:
return 0;
case SCC_DMA_Rcv_B_Ctrl: {
uint32_t value = std::rand() & (-1U >> (32 - size * 8));
LOG_F(WARNING, "AMIC SCC Receive Ch B DMA Ctrl read @%x.%c = %0*x",
offset, SIZE_ARG(size), size * 2, value);
return value;
}
default:
LOG_F(WARNING, "Unknown AMIC register read, offset=%x", offset);
}
@@ -400,9 +420,9 @@ void AMIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
if (value & 2) { // RUN bit set?
this->curio_dma->reinit(this->scsi_dma_base);
if (value & (1 << 6))
this->scsi->real_dma_xfer_out();
this->curio_dma->xfer_to_device();
else
this->scsi->real_dma_xfer_in();
this->curio_dma->xfer_from_device();
}
this->curio_dma->write_ctrl(value);
break;
@@ -735,25 +755,50 @@ void AmicScsiDma::write_ctrl(uint8_t value)
}
}
int AmicScsiDma::push_data(const char* src_ptr, int len)
{
MapDmaResult res = mmu_map_dma_mem(this->addr_ptr, len, false);
uint8_t *p_data = res.host_va;
std::memcpy(p_data, src_ptr, len);
this->addr_ptr += len;
return 0;
bool AmicScsiDma::is_ready() {
return (this->stat & 2) ? true : false;
}
DmaPullResult AmicScsiDma::pull_data(uint32_t req_len, uint32_t *avail_len,
uint8_t **p_data)
{
MapDmaResult res = mmu_map_dma_mem(this->addr_ptr, req_len, false);
*p_data = res.host_va;
this->addr_ptr += req_len;
*avail_len = req_len;
return DmaPullResult::MoreData;
void AmicScsiDma::xfer_from_device() {
if (this->dev_obj == nullptr)
return;
this->xfer_dir = DMA_DIR_FROM_DEV;
uint32_t len = this->dev_obj->tell_xfer_size();
MapDmaResult res = mmu_map_dma_mem(this->addr_ptr, len, false);
int got_bytes = this->dev_obj->xfer_from(res.host_va, len);
if (got_bytes > 0) {
this->addr_ptr += got_bytes;
}
}
void AmicScsiDma::xfer_to_device() {
if (this->dev_obj == nullptr)
return;
this->xfer_dir = DMA_DIR_TO_DEV;
uint32_t len = this->dev_obj->tell_xfer_size();
MapDmaResult res = mmu_map_dma_mem(this->addr_ptr, len, false);
int got_bytes = this->dev_obj->xfer_to(res.host_va, len);
if (got_bytes > 0) {
this->addr_ptr += got_bytes;
}
}
void AmicScsiDma::xfer_retry() {
if (this->xfer_dir == DMA_DIR_UNDEF)
return;
if (this->xfer_dir == DMA_DIR_FROM_DEV)
this->xfer_from_device();
else
this->xfer_to_device();
}
// =========================== Serial DMA stuff ===============================
+21 -12
View File
@@ -175,19 +175,21 @@ private:
};
/** AMIC-specific SCSI DMA implementation. */
class AmicScsiDma : public DmaBidirChannel {
class AmicScsiDma : public DmaChannel {
public:
AmicScsiDma() : DmaBidirChannel("Scsi") {}
~AmicScsiDma() = default;
AmicScsiDma() = default;
~AmicScsiDma() = default;
void reinit(const uint32_t addr_ptr);
void reset(const uint32_t addr_ptr);
void write_ctrl(const uint8_t value);
uint8_t read_stat() { return this->stat; };
int push_data(const char* src_ptr, int len);
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
uint8_t **p_data);
void xfer_to_device();
void xfer_from_device();
bool is_ready() override;
void xfer_retry() override;
private:
uint32_t addr_ptr;
@@ -230,10 +232,11 @@ enum AMICReg : uint32_t {
Ariel_Config = 0x24002,
// VIA2 registers
// = 0x26000,
// = 0x26000, // byte, write 0x8f
VIA2_Slot_IFR = 0x26002,
VIA2_IFR = 0x26003,
// = 0x26010,
// = 0x26004, // byte, read
// = 0x26010, // byte, write 0x40
VIA2_Slot_IER = 0x26012,
VIA2_IER = 0x26013,
VIA2_IFR_RBV = 0x27A03, // RBV-compatible mirror for the VIA2_IFR
@@ -279,12 +282,18 @@ enum AMICReg : uint32_t {
Floppy_DMA_Ctrl = 0x32068,
SCC_DMA_Xmt_A_Ctrl = 0x32088,
SCC_RXA_Byte_Cnt_Hi = 0x32094, // 5 bits, read-only
SCC_RXA_Byte_Cnt_Lo = 0x32095, // 8 bits, read-only
// = 0x32092, // byte, read
// = 0x32093, // byte, read
SCC_RXA_Byte_Cnt_Hi = 0x32094, // 5 bits, read; byte, write 0x10
SCC_RXA_Byte_Cnt_Lo = 0x32095, // 8 bits, read; byte, write 0x00
SCC_DMA_Rcv_A_Ctrl = 0x32098,
// = 0x320A4, // byte, write 0x00
// = 0x320A5, // byte, write 0x07
SCC_DMA_Xmt_B_Ctrl = 0x320A8,
SCC_RXB_Byte_Cnt_Hi = 0x320B4, // 5 bits, read-only
SCC_RXB_Byte_Cnt_Lo = 0x320B5, // 8 bits, read-only
// = 0x320B2, // byte, read
// = 0x320B3, // byte, read
SCC_RXB_Byte_Cnt_Hi = 0x320B4, // 5 bits, read; byte, write 0x10
SCC_RXB_Byte_Cnt_Lo = 0x320B5, // 8 bits, read; byte, write 0x00
SCC_DMA_Rcv_B_Ctrl = 0x320B8,
};
+42 -6
View File
@@ -172,8 +172,28 @@ void GrandCentral::notify_bar_change(int bar_num)
}
}
static const char *get_name_dma(unsigned dma_channel) {
switch (dma_channel) {
case MIO_GC_DMA_SCSI_CURIO : return "DMA_SCSI_CURIO" ;
case MIO_GC_DMA_FLOPPY : return "DMA_FLOPPY" ;
case MIO_GC_DMA_ETH_XMIT : return "DMA_ETH_XMIT" ;
case MIO_GC_DMA_ETH_RCV : return "DMA_ETH_RCV" ;
case MIO_GC_DMA_ESCC_A_XMIT : return "DMA_ESCC_A_XMIT";
case MIO_GC_DMA_ESCC_A_RCV : return "DMA_ESCC_A_RCV" ;
case MIO_GC_DMA_ESCC_B_XMIT : return "DMA_ESCC_B_XMIT";
case MIO_GC_DMA_ESCC_B_RCV : return "DMA_ESCC_B_RCV" ;
case MIO_GC_DMA_AUDIO_OUT : return "DMA_AUDIO_OUT" ;
case MIO_GC_DMA_AUDIO_IN : return "DMA_AUDIO_IN" ;
case MIO_GC_DMA_SCSI_MESH : return "DMA_SCSI_MESH" ;
default : return "unknown" ;
}
}
static uint8_t ENET_ROM[] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 };
// The first 3 bytes of a MAC address is an OUI for "Apple, Inc."
// A MAC address cannot begin with 0x10 because that will get bit-flipped to 0x08.
// A MAC address that begins with 0x08 can be stored as bit-flipped or not bit-flipped.
static uint8_t mac_address[] = { 0x08, 0x00, 0x07, 0x44, 0x55, 0x66, 0x00, 0x00 };
static bool bit_flip_0x08 = false;
uint32_t GrandCentral::read(uint32_t rgn_start, uint32_t offset, int size)
{
@@ -206,7 +226,17 @@ uint32_t GrandCentral::read(uint32_t rgn_start, uint32_t offset, int size)
case 8: // MESH SCSI
return this->mesh->read((offset >> 4) & 0xF);
case 9: // ENET-ROM
return ENET_ROM[(offset >> 4) & 0x7];
{
uint8_t val = mac_address[(offset >> 4) & 0x7];
if (((offset >> 4) & 0x7) < 6) {
if (mac_address[0] == 0x08 && bit_flip_0x08)
val = (val * 0x0202020202ULL & 0x010884422010ULL) % 1023;
} else {
LOG_F(WARNING, "%s: reading byte %d of ENET_ROM using offset %x",
this->name.c_str(), (offset >> 4) & 0x7, offset);
}
return val;
}
case 0xA: // IOBus device #1 ; Board register 1 and bandit1 PRSNT bits
case 0xB: // IOBus device #2 ; RaDACal/DACula
case 0xC: // IOBus device #3 ; chaos or bandit2 PRSNT bits ; sixty6
@@ -264,8 +294,11 @@ uint32_t GrandCentral::read(uint32_t rgn_start, uint32_t offset, int size)
}
// fallthrough
default:
LOG_F(WARNING, "%s: unimplemented DMA register at 0x%X",
this->name.c_str(), this->base_addr + offset);
if (!(unsupported_dma_channel_read & (1 << dma_channel))) {
unsupported_dma_channel_read |= (1 << dma_channel);
LOG_F(WARNING, "%s: Unsupported DMA channel %d %s read @%02x.%c", this->name.c_str(),
dma_channel, get_name_dma(dma_channel), offset & 0xFF, SIZE_ARG(size));
}
}
} else { // Interrupt related registers
switch (offset) {
@@ -398,8 +431,11 @@ void GrandCentral::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
}
// fallthrough
default:
LOG_F(WARNING, "%s: unimplemented DMA register at 0x%X",
this->name.c_str(), this->base_addr + offset);
if (!(unsupported_dma_channel_write & (1 << dma_channel))) {
unsupported_dma_channel_write |= (1 << dma_channel);
LOG_F(WARNING, "%s: Unsupported DMA channel %d %s write @%02x.%c = %0*x", this->name.c_str(),
dma_channel, get_name_dma(dma_channel), offset & 0xFF, SIZE_ARG(size), size * 2, value);
}
}
} else { // Interrupt related registers
switch (offset) {
+35 -4
View File
@@ -80,6 +80,9 @@ HeathrowIC::HeathrowIC() : PCIDevice("mac-io_heathrow"), InterruptCtrl()
// connect SCSI HW and the corresponding DMA channel
this->mesh = dynamic_cast<MeshController*>(gMachineObj->get_comp_by_name("MeshHeathrow"));
this->mesh_dma = std::unique_ptr<DMAChannel> (new DMAChannel("mesh"));
this->mesh_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SCSI_MESH));
this->mesh_dma->connect(this->mesh);
this->mesh->connect(this->mesh_dma.get());
// connect IDE HW
this->ide_0 = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name("Ide0"));
@@ -106,6 +109,24 @@ HeathrowIC::HeathrowIC() : PCIDevice("mac-io_heathrow"), InterruptCtrl()
this->emmo_pin = GET_BIN_PROP("emmo") ^ 1;
}
static const char *get_name_dma(unsigned dma_channel) {
switch (dma_channel) {
case MIO_OHARE_DMA_MESH : return "DMA_MESH" ;
case MIO_OHARE_DMA_FLOPPY : return "DMA_FLOPPY" ;
case MIO_OHARE_DMA_ETH_XMIT : return "DMA_ETH_XMIT" ;
case MIO_OHARE_DMA_ETH_RCV : return "DMA_ETH_RCV" ;
case MIO_OHARE_DMA_ESCC_A_XMIT : return "DMA_ESCC_A_XMIT";
case MIO_OHARE_DMA_ESCC_A_RCV : return "DMA_ESCC_A_RCV" ;
case MIO_OHARE_DMA_ESCC_B_XMIT : return "DMA_ESCC_B_XMIT";
case MIO_OHARE_DMA_ESCC_B_RCV : return "DMA_ESCC_B_RCV" ;
case MIO_OHARE_DMA_AUDIO_OUT : return "DMA_AUDIO_OUT" ;
case MIO_OHARE_DMA_AUDIO_IN : return "DMA_AUDIO_IN" ;
case MIO_OHARE_DMA_IDE0 : return "DMA_IDE0" ;
case MIO_OHARE_DMA_IDE1 : return "DMA_IDE1" ;
default : return "unknown" ;
}
}
void HeathrowIC::set_media_bay_id(uint8_t id) {
this->mb_id = id;
}
@@ -126,7 +147,8 @@ void HeathrowIC::notify_bar_change(int bar_num)
}
uint32_t HeathrowIC::dma_read(uint32_t offset, int size) {
switch (offset >> 8) {
int dma_channel = offset >> 8;
switch (dma_channel) {
case MIO_OHARE_DMA_MESH:
if (this->mesh_dma)
return this->mesh_dma->reg_read(offset & 0xFF, size);
@@ -143,14 +165,19 @@ uint32_t HeathrowIC::dma_read(uint32_t offset, int size) {
case MIO_OHARE_DMA_AUDIO_OUT:
return this->snd_out_dma->reg_read(offset & 0xFF, size);
default:
LOG_F(WARNING, "Unsupported DMA channel read, offset=0x%X", offset);
if (!(unsupported_dma_channel_read & (1 << dma_channel))) {
unsupported_dma_channel_read |= (1 << dma_channel);
LOG_F(WARNING, "%s: Unsupported DMA channel %d %s read @%02x.%c", this->name.c_str(),
dma_channel, get_name_dma(dma_channel), offset & 0xFF, SIZE_ARG(size));
}
}
return 0;
}
void HeathrowIC::dma_write(uint32_t offset, uint32_t value, int size) {
switch (offset >> 8) {
int dma_channel = offset >> 8;
switch (dma_channel) {
case MIO_OHARE_DMA_MESH:
if (this->mesh_dma) this->mesh_dma->reg_write(offset & 0xFF, value, size);
break;
@@ -170,7 +197,11 @@ void HeathrowIC::dma_write(uint32_t offset, uint32_t value, int size) {
this->snd_out_dma->reg_write(offset & 0xFF, value, size);
break;
default:
LOG_F(WARNING, "Unsupported DMA channel write, offset=0x%X, val=0x%X", offset, value);
if (!(unsupported_dma_channel_write & (1 << dma_channel))) {
unsupported_dma_channel_write |= (1 << dma_channel);
LOG_F(WARNING, "%s: Unsupported DMA channel %d %s write @%02x.%c = %0*x", this->name.c_str(),
dma_channel, get_name_dma(dma_channel), offset & 0xFF, SIZE_ARG(size), size * 2, value);
}
}
}
+5 -1
View File
@@ -312,7 +312,8 @@ enum {
/** MIO_OHARE_FEAT_CTRL bits. */
enum {
MIO_OH_FC_IN_USE_LED = 1 << 0,
MIO_OH_FC_IN_USE_LED = 1 << 0, // modem serial port in use in Open Firmware
// controls display sense on Beige G3 desktop
MIO_OH_FC_NOT_MB_PWR = 1 << 1,
MIO_OH_FC_PCI_MB_EN = 1 << 2,
MIO_OH_FC_IDE_MB_EN = 1 << 3,
@@ -435,6 +436,9 @@ private:
std::unique_ptr<DMAChannel> enet_rcv_dma;
std::unique_ptr<DMAChannel> escc_b_rcv_dma;
std::unique_ptr<DMAChannel> snd_out_dma;
uint16_t unsupported_dma_channel_read = 0;
uint16_t unsupported_dma_channel_write = 0;
};
#endif /* MACIO_H */
+25 -1
View File
@@ -106,6 +106,24 @@ OHare::OHare() : PCIDevice("mac-io_ohare"), InterruptCtrl()
//this->emmo_pin = GET_BIN_PROP("emmo") ^ 1;
}
static const char *get_name_dma(unsigned dma_channel) {
switch (dma_channel) {
case MIO_OHARE_DMA_MESH : return "DMA_MESH" ;
case MIO_OHARE_DMA_FLOPPY : return "DMA_FLOPPY" ;
case MIO_OHARE_DMA_ETH_XMIT : return "DMA_ETH_XMIT" ;
case MIO_OHARE_DMA_ETH_RCV : return "DMA_ETH_RCV" ;
case MIO_OHARE_DMA_ESCC_A_XMIT : return "DMA_ESCC_A_XMIT";
case MIO_OHARE_DMA_ESCC_A_RCV : return "DMA_ESCC_A_RCV" ;
case MIO_OHARE_DMA_ESCC_B_XMIT : return "DMA_ESCC_B_XMIT";
case MIO_OHARE_DMA_ESCC_B_RCV : return "DMA_ESCC_B_RCV" ;
case MIO_OHARE_DMA_AUDIO_OUT : return "DMA_AUDIO_OUT" ;
case MIO_OHARE_DMA_AUDIO_IN : return "DMA_AUDIO_IN" ;
case MIO_OHARE_DMA_IDE0 : return "DMA_IDE0" ;
case MIO_OHARE_DMA_IDE1 : return "DMA_IDE1" ;
default : return "unknown" ;
}
}
void OHare::notify_bar_change(int bar_num)
{
if (bar_num) // only BAR0 is supported
@@ -320,6 +338,8 @@ uint32_t OHare::dma_read(uint32_t offset, int size)
default:
if (!(unsupported_dma_channel_read & (1 << dma_channel))) {
unsupported_dma_channel_read |= (1 << dma_channel);
LOG_F(WARNING, "%s: Unsupported DMA channel %d %s read @%02x.%c", this->name.c_str(),
dma_channel, get_name_dma(dma_channel), offset & 0xFF, SIZE_ARG(size));
return 0;
}
value = 0;
@@ -342,7 +362,11 @@ void OHare::dma_write(uint32_t offset, uint32_t value, int size)
this->snd_out_dma->reg_write(offset & 0xFF, value, size);
break;
default:
LOG_F(WARNING, "OHare: unsupported DMA channel write, offset=0x%X, val=0x%X", offset, value);
if (!(unsupported_dma_channel_write & (1 << dma_channel))) {
unsupported_dma_channel_write |= (1 << dma_channel);
LOG_F(WARNING, "%s: Unsupported DMA channel %d %s write @%02x.%c = %0*x", this->name.c_str(),
dma_channel, get_name_dma(dma_channel), offset & 0xFF, SIZE_ARG(size), size * 2, value);
}
}
}
+7 -5
View File
@@ -47,10 +47,11 @@ uint32_t HammerheadCtrl::read(uint32_t rgn_start, uint32_t offset, int size)
if (offset >= HammerheadReg::BANK_0_BASE_MSB &&
offset <= HammerheadReg::BANK_25_BASE_LSB) {
offset = (offset - HammerheadReg::BANK_0_BASE_MSB) >> 4;
int bank = offset >> 1;
if (offset & 1) { // return the LSB part
result = bank_base[offset >> 1] & 0xFFU;
result = bank_base[bank] & 0xFFU;
} else { // return the MSB part
result = bank_base[offset >> 1] >> 8;
result = bank_base[bank] >> 8;
}
goto finish;
}
@@ -94,13 +95,14 @@ void HammerheadCtrl::write(uint32_t rgn_start, uint32_t offset, uint32_t value,
if (offset >= HammerheadReg::BANK_0_BASE_MSB &&
offset <= HammerheadReg::BANK_25_BASE_LSB) {
offset = (offset - HammerheadReg::BANK_0_BASE_MSB) >> 4;
int bank = offset >> 1;
if (offset & 1) { // update the LSB part
bank_base[offset >> 1] = (bank_base[offset >> 1] & 0xFF00U) | value;
bank_base[bank] = (bank_base[bank] & 0xFF00U) | value;
} else { // update the MSB part
bank_base[offset >> 1] = (bank_base[offset >> 1] & 0x00FFU) | (value << 8);
bank_base[bank] = (bank_base[bank] & 0x00FFU) | (value << 8);
}
LOG_F(INFO, "%s: bank base #%d set to 0x%X", this->name.c_str(),
offset >> 1, bank_base[offset >> 1]);
bank, bank_base[bank]);
return;
}
+12 -1
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -62,6 +62,11 @@ namespace Hammerhead {
BUS_SPEED_50_MHZ = 3
};
// bits for the ARBITER_CONFIG register
enum {
TWO_CPU = 1 << 1,
};
// bus master IDs for the WHO_AM_I register
enum {
BM_VIDEO_BRIDGE = 1 << 4,
@@ -71,6 +76,11 @@ namespace Hammerhead {
BM_SECONDARY_CPU = 1 << 0
};
// Interrupt bits for the INT_REG register
enum {
SEC_INT = 1 << 7,
};
// Configuration and status registers.
enum HammerheadReg : uint16_t {
CPU_ID = 0x00,
@@ -85,6 +95,7 @@ namespace Hammerhead {
ARBITER_CONFIG = 0x90,
ARBUS_TIMEOUT = 0xA0,
WHO_AM_I = 0xB0,
INT_REG = 0xC0,
L2_CACHE_CONFIG = 0xE0,
BANK_0_BASE_MSB = 0x1C0,
BANK_25_BASE_LSB = 0x4F0,
+118 -26
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -42,6 +42,51 @@ MemCtrlBase::~MemCtrlBase() {
this->address_map.clear();
}
static std::string get_type_str(uint32_t type) {
std::string str;
if (type & RT_ROM) {
if (str.length())
str += ",";
str += "ROM";
};
if (type & RT_RAM) {
if (str.length())
str += ",";
str += "RAM";
};
if (type & RT_MMIO) {
if (str.length())
str += ",";
str += "MMIO";
};
if (type & RT_MIRROR) {
if (str.length())
str += ",";
str += "MIRROR";
};
return str;
}
static std::string get_entry_str(const AddressMapEntry* entry) {
std::string str;
char buf[50];
if (entry) {
snprintf(buf, sizeof(buf), "0x%08X..0x%08X", entry->start, entry->end);
str = std::string(buf) + " (" + get_type_str(entry->type) + ")";
if (entry->devobj)
str += " (" + entry->devobj->get_name() + ")";
if (entry->type & RT_MIRROR) {
snprintf(buf, sizeof(buf), " -> 0x%08X..0x%08X", entry->mirror,
entry->mirror + entry->end - entry->start);
str += std::string(buf);
}
} else {
str = "null";
}
return str;
}
static inline bool match_mem_entry(const AddressMapEntry* entry,
const uint32_t start, const uint32_t end,
@@ -144,19 +189,20 @@ bool MemCtrlBase::is_range_free(uint32_t addr, uint32_t size) {
}
bool MemCtrlBase::add_mem_region(uint32_t start_addr, uint32_t size,
uint32_t dest_addr, uint32_t type,
uint8_t init_val = 0)
AddressMapEntry* MemCtrlBase::add_mem_region(uint32_t start_addr, uint32_t size,
uint32_t dest_addr, uint32_t type,
uint8_t *mem_ptr = nullptr)
{
AddressMapEntry *entry;
// bail out if a memory region for the given range already exists
if (!is_range_free(start_addr, size))
return false;
return nullptr;
uint8_t* reg_content = new uint8_t[size](); // allocate and clear to zero
this->mem_regions.push_back(reg_content);
if (!mem_ptr) {
mem_ptr = new uint8_t[size](); // allocate and clear to zero
this->mem_regions.push_back(mem_ptr);
}
entry = new AddressMapEntry;
@@ -166,7 +212,7 @@ bool MemCtrlBase::add_mem_region(uint32_t start_addr, uint32_t size,
entry->mirror = dest_addr;
entry->type = type;
entry->devobj = nullptr;
entry->mem_ptr = reg_content;
entry->mem_ptr = mem_ptr;
// Keep address_map sorted, that way the RAM region (which starts at 0 and
// is most often requested) will be found by find_range on the first
@@ -189,27 +235,32 @@ bool MemCtrlBase::add_mem_region(uint32_t start_addr, uint32_t size,
dest_addr
);
return true;
return entry;
}
bool MemCtrlBase::add_rom_region(uint32_t start_addr, uint32_t size) {
AddressMapEntry* MemCtrlBase::add_rom_region(uint32_t start_addr, uint32_t size) {
return add_mem_region(start_addr, size, 0, RT_ROM);
}
bool MemCtrlBase::add_ram_region(uint32_t start_addr, uint32_t size) {
AddressMapEntry* MemCtrlBase::add_ram_region(uint32_t start_addr, uint32_t size) {
return add_mem_region(start_addr, size, 0, RT_RAM);
}
AddressMapEntry* MemCtrlBase::add_ram_region(uint32_t start_addr, uint32_t size,
uint8_t *mem_ptr) {
return add_mem_region(start_addr, size, 0, RT_RAM, mem_ptr);
}
bool MemCtrlBase::add_mem_mirror_common(uint32_t start_addr, uint32_t dest_addr,
uint32_t offset, uint32_t size) {
AddressMapEntry* MemCtrlBase::add_mem_mirror_common(uint32_t start_addr, uint32_t dest_addr,
uint32_t offset, uint32_t size) {
AddressMapEntry *entry, *ref_entry;
ref_entry = find_range(dest_addr);
if (!ref_entry)
return false;
return nullptr;
// use origin's size if no size was specified
if (!size)
@@ -218,7 +269,7 @@ bool MemCtrlBase::add_mem_mirror_common(uint32_t start_addr, uint32_t dest_addr,
if (ref_entry->start + offset + size - 1 > ref_entry->end) {
LOG_F(ERROR, "Partial mirror outside the origin, offset=0x%X, size=0x%X",
offset, size);
return false;
return nullptr;
}
entry = new AddressMapEntry;
@@ -247,45 +298,45 @@ bool MemCtrlBase::add_mem_mirror_common(uint32_t start_addr, uint32_t dest_addr,
: ""
);
return true;
return entry;
}
bool MemCtrlBase::add_mem_mirror(uint32_t start_addr, uint32_t dest_addr) {
AddressMapEntry* MemCtrlBase::add_mem_mirror(uint32_t start_addr, uint32_t dest_addr) {
return this->add_mem_mirror_common(start_addr, dest_addr);
}
bool MemCtrlBase::add_mem_mirror_partial(uint32_t start_addr, uint32_t dest_addr,
uint32_t offset, uint32_t size) {
AddressMapEntry* MemCtrlBase::add_mem_mirror_partial(uint32_t start_addr, uint32_t dest_addr,
uint32_t offset, uint32_t size) {
return this->add_mem_mirror_common(start_addr, dest_addr, offset, size);
}
bool MemCtrlBase::set_data(uint32_t load_addr, const uint8_t* data, uint32_t size) {
AddressMapEntry* MemCtrlBase::set_data(uint32_t load_addr, const uint8_t* data, uint32_t size) {
AddressMapEntry* ref_entry;
uint32_t cpy_size;
ref_entry = find_range(load_addr);
if (!ref_entry)
return false;
return nullptr;
uint32_t load_offset = load_addr - ref_entry->start;
cpy_size = std::min(ref_entry->end - ref_entry->start + 1, size);
memcpy(ref_entry->mem_ptr + load_offset, data, cpy_size);
return true;
return ref_entry;
}
bool MemCtrlBase::add_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice* dev_instance)
AddressMapEntry* MemCtrlBase::add_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice* dev_instance)
{
AddressMapEntry *entry;
// bail out if a memory region for the given range already exists
if (!is_range_free(start_addr, size))
return false;
return nullptr;
entry = new AddressMapEntry;
@@ -307,9 +358,10 @@ bool MemCtrlBase::add_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice
: ""
);
return true;
return entry;
}
bool MemCtrlBase::remove_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice* dev_instance)
{
int found = 0;
@@ -351,6 +403,36 @@ bool MemCtrlBase::remove_mmio_region(uint32_t start_addr, uint32_t size, MMIODev
return (found > 0);
}
AddressMapEntry* MemCtrlBase::remove_region(AddressMapEntry* entry)
{
int found = 0;
address_map.erase(std::remove_if(address_map.begin(), address_map.end(),
[entry, &found](const AddressMapEntry *cmp_entry) {
if (entry == cmp_entry) {
if (found)
LOG_F(ERROR, "Removed mem region %s", get_entry_str(entry).c_str());
else
LOG_F(INFO, "Removed mem region %s", get_entry_str(entry).c_str());
found++;
return true;
}
return false;
}
), address_map.end());
if (found == 0) {
LOG_F(ERROR, "Cannot find mem region %s to remove",
get_entry_str(entry).c_str()
);
return nullptr;
}
return entry;
}
AddressMapEntry* MemCtrlBase::find_rom_region()
{
for (auto& entry : address_map) {
@@ -372,3 +454,13 @@ uint8_t *MemCtrlBase::get_region_hostmem_ptr(const uint32_t addr) {
else
return (addr - reg_desc->start) + reg_desc->mem_ptr;
}
void MemCtrlBase::dump_regions()
{
int i = 0;
for (auto& entry : address_map) {
printf("%2d: %s\n", i, get_entry_str(entry).c_str());
i++;
}
}
+18 -13
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -64,18 +64,21 @@ class MemCtrlBase {
public:
MemCtrlBase() = default;
virtual ~MemCtrlBase();
virtual bool add_rom_region(uint32_t start_addr, uint32_t size);
virtual bool add_ram_region(uint32_t start_addr, uint32_t size);
virtual bool add_mem_mirror(uint32_t start_addr, uint32_t dest_addr);
virtual bool add_mem_mirror_partial(uint32_t start_addr, uint32_t dest_addr,
uint32_t offset, uint32_t size);
virtual AddressMapEntry* add_rom_region(uint32_t start_addr, uint32_t size);
virtual AddressMapEntry* add_ram_region(uint32_t start_addr, uint32_t size);
virtual AddressMapEntry* add_ram_region(uint32_t start_addr, uint32_t size,
uint8_t *mem_ptr);
virtual AddressMapEntry* add_mem_mirror(uint32_t start_addr, uint32_t dest_addr);
virtual AddressMapEntry* add_mem_mirror_partial(uint32_t start_addr, uint32_t dest_addr,
uint32_t offset, uint32_t size);
virtual bool add_mmio_region(uint32_t start_addr, uint32_t size,
MMIODevice* dev_instance);
virtual AddressMapEntry* add_mmio_region(uint32_t start_addr, uint32_t size,
MMIODevice* dev_instance);
virtual bool remove_mmio_region(uint32_t start_addr, uint32_t size,
MMIODevice* dev_instance);
virtual AddressMapEntry* remove_region(AddressMapEntry* entry);
virtual bool set_data(uint32_t reg_addr, const uint8_t* data, uint32_t size);
virtual AddressMapEntry* set_data(uint32_t reg_addr, const uint8_t* data, uint32_t size);
AddressMapEntry* find_range(uint32_t addr);
AddressMapEntry* find_range_exact(uint32_t addr, uint32_t size,
@@ -88,14 +91,16 @@ public:
uint8_t *get_region_hostmem_ptr(const uint32_t addr);
void dump_regions();
protected:
bool add_mem_region(
AddressMapEntry* add_mem_region(
uint32_t start_addr, uint32_t size, uint32_t dest_addr, uint32_t type,
uint8_t init_val
uint8_t *mem_ptr
);
bool add_mem_mirror_common(uint32_t start_addr, uint32_t dest_addr,
uint32_t offset=0, uint32_t size=0);
AddressMapEntry* add_mem_mirror_common(uint32_t start_addr, uint32_t dest_addr,
uint32_t offset=0, uint32_t size=0);
private:
std::vector<uint8_t*> mem_regions;
+24 -9
View File
@@ -251,16 +251,23 @@ void MPC106::setup_ram() {
// get non-empty banks
for (int bank = 0; bank < 8; bank++) {
if (this->mem_bank_en & (1 << bank)) {
int b = (bank >= 4);
bank_start[bank_count] = (((ext_mem_start[b] >> bank * 8) & 3) << 28) |
(((mem_start[b] >> bank * 8) & 0xFF) << 20);
bank_end[bank_count] = (((ext_mem_end[b] >> bank * 8) & 3) << 28) |
(((mem_end[b] >> bank * 8) & 0xFF) << 20) | 0xFFFFFUL;
int word = bank >> 2;
int byte = bank & 3;
int shift = byte * 8;
bank_start[bank_count] = (((ext_mem_start[word] >> shift) & 3) << 28) |
((((mem_start[word]) >> shift) & 0xFF) << 20);
bank_end [bank_count] = (((ext_mem_end [word] >> shift) & 3) << 28) |
((((mem_end [word]) >> shift) & 0xFF) << 20) | 0xFFFFFU;
bank_order[bank_count] = bank_count;
bank_count++;
}
}
LOG_F(INFO, "banks:");
for (int i = 0; i < bank_count; i++) {
LOG_F(INFO, "bank %d: [%08X..%08X]", i, bank_start[i], bank_end[i]);
}
// sort banks by start address
for (int i = 0; i < bank_count; i++) {
for (int j = i + 1; j < bank_count; j++) {
@@ -272,16 +279,24 @@ void MPC106::setup_ram() {
}
}
// squash adjacent banks into memory regions
// squash adjacent or overlapping banks into memory regions
bool overlapping_regions = false;
for (int i = 0; i < bank_count; i++) {
if (region_count > 0 && bank_start[bank_order[i]] == bank_end[bank_order[region_count - 1]] + 1)
bank_end[bank_order[region_count - 1]] = bank_end[bank_order[i]];
else {
if (region_count > 0 && bank_start[bank_order[i]] <= bank_end[bank_order[region_count - 1]] + 1) {
if (bank_start[bank_order[i]] < bank_end[bank_order[region_count - 1]] + 1) {
overlapping_regions = true;
}
if (bank_end[bank_order[i]] > bank_end[bank_order[region_count - 1]])
bank_end[bank_order[region_count - 1]] = bank_end[bank_order[i]];
} else {
bank_order[region_count] = bank_order[i];
region_count++;
}
}
if (overlapping_regions)
LOG_F(ERROR, "overlapping regions");
// allocate memory regions
for (int i = 0; i < region_count; i++) {
uint32_t region_size = bank_end[bank_order[i]] - bank_start[bank_order[i]] + 1;
+93 -1
View File
@@ -65,9 +65,101 @@ enum GrackleReg : uint32_t {
MCCR4 = 0xFC // memory control configuration 4
};
/* PICR1 bit definitions. */
enum {
CF_L2_MP_SHIFT = 0,
CF_L2_MP_MASK = 3 << CF_L2_MP_SHIFT,
SPECULATIVE_PCI_READS = 1 << 2,
CF_APARK = 1 << 3,
CF_LOOP_SNOOP = 1 << 4,
LE_MODE = 1 << 5,
ST_GATH_EN = 1 << 6,
NO_PORT_REGS = 1 << 7,
CF_EXTERNAL_L2 = 1 << 8,
CF_DPARK = 1 << 9,
TEA_EN = 1 << 10, // enabled during ROM flashing
MCP_EN = 1 << 11,
FLASH_WR_EN = 1 << 12, // enabled during ROM flashing, disabled after ROM flashing
CF_LBA_EN = 1 << 13,
CF_MP_ID_SHIFT = 14,
CF_MP_ID_MASK = 3 << CF_MP_ID_SHIFT,
ADDRESS_MAP = 1 << 16,
PROC_TYPE_SHIFT = 17,
PROC_TYPE_MASK = 3 << PROC_TYPE_SHIFT,
XIO_MODE = 1 << 19,
RCS0 = 1 << 20,
CF_CACHE_1G = 1 << 21,
CF_BREAD_WS_SHIFT = 22,
CF_BREAD_WS_MASK = 3 << CF_BREAD_WS_SHIFT,
CF_CBA_MASK_SHIFT = 24,
CF_CBA_MASK_MASK = 0xff << CF_CBA_MASK_SHIFT,
};
/* PICR2 bit definitions. */
enum {
CF_WDATA = 0,
CF_DOE = 1,
CF_APHASE_WS_SHIFT = 2,
CF_APHASE_WS_MASK = 3 << CF_APHASE_WS_SHIFT,
CF_L2_SIZE_SHIFT = 4,
CF_L2_SIZE_MASK = 3 << CF_L2_SIZE_SHIFT,
CF_TOE_WIDTH = 6,
CF_FAST_CASTOUT = 7,
CF_TWO_BANKS = 8,
CF_L2_HIT_DELAY_SHIFT = 9,
CF_L2_HIT_DELAY_MASK = 3 << CF_L2_HIT_DELAY_SHIFT,
CF_RWITM_FILL = 11,
CF_INV_MODE = 12,
CF_HOLD = 13,
CF_ADDR_ONLY_DISABLE = 14,
// RESERVED = 15,
CF_HIT_HIGH = 16,
CF_MOD_HIGH = 17,
CF_SNOOP_WS_SHIFT = 18,
CF_SNOOP_WS_MASK = 3 << CF_SNOOP_WS_SHIFT,
CF_WMODE_SHIFT = 20,
CF_WMODE_MASK = 3 << CF_WMODE_SHIFT,
CF_DATA_RAM_TYPE_SHIFT = 22,
CF_DATA_RAM_TYPE_MASK = 3 << CF_DATA_RAM_TYPE_SHIFT,
CF_FAST_L2_MODE = 24,
FLASH_WR_LOCKOUT = 25, // Programmer Mode changes this to 0 which allows flash writing.
CF_FF0_LOCAL = 26,
NO_SNOOP_EN = 27,
CF_FLUSH_L2 = 28,
NO_SERIAL_CFG = 29,
L2_EN = 30,
L2_UPDATE_EN = 31,
};
/* MCCR1 bit definitions. */
enum {
MEMGO = 1 << 19,
BANK_0_ROW_SHIFT = 0,
BANK_0_ROW_MASK = 3 << BANK_0_ROW_SHIFT,
BANK_1_ROW_SHIFT = 2,
BANK_1_ROW_MASK = 3 << BANK_1_ROW_SHIFT,
BANK_2_ROW_SHIFT = 4,
BANK_2_ROW_MASK = 3 << BANK_2_ROW_SHIFT,
BANK_3_ROW_SHIFT = 6,
BANK_3_ROW_MASK = 3 << BANK_3_ROW_SHIFT,
BANK_4_ROW_SHIFT = 8,
BANK_4_ROW_MASK = 3 << BANK_4_ROW_SHIFT,
BANK_5_ROW_SHIFT = 10,
BANK_5_ROW_MASK = 3 << BANK_5_ROW_SHIFT,
BANK_6_ROW_SHIFT = 12,
BANK_6_ROW_MASK = 3 << BANK_6_ROW_SHIFT,
BANK_7_ROW_SHIFT = 14,
BANK_7_ROW_MASK = 3 << BANK_7_ROW_SHIFT,
PCKEN = 1 << 16,
RAM_TYPE = 1 << 17,
SREN = 1 << 18,
MEMGO = 1 << 19,
BURST = 1 << 20,
_8N64 = 1 << 21, // 1 = the MPC106 is configured for an 8-bit data path for ROM bank 0 rather than 64-bit
_501_MODE = 1 << 22,
ROMFAL_SHIFT = 23,
ROMFAL_MASK = 31 << ROMFAL_SHIFT,
ROMNAL_SHIFT = 28,
ROMNAL_MASK = 15 << ROMNAL_SHIFT,
};
class MPC106 : public MemCtrlBase, public PCIDevice, public PCIHost {
+56 -6
View File
@@ -242,6 +242,7 @@ void PlatinumCtrl::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
case PlatinumReg::BANK_6_BASE:
case PlatinumReg::BANK_7_BASE:
this->bank_base[(offset >> 4) - PlatinumReg::BANK_0_BASE] = value;
this->map_phys_ram();
break;
case PlatinumReg::FB_BASE_ADDR:
this->fb_addr = value;
@@ -406,12 +407,54 @@ void PlatinumCtrl::map_phys_ram() {
total_ram += this->bank_size[i];
}
if (total_ram > DRAM_CAP_64MB) {
ABORT_F("%s: RAM bigger than 64MB not supported yet", this->name.c_str());
if (!this->dram_ptr) {
this->dram_ptr = std::unique_ptr<uint8_t[]> (new uint8_t[total_ram]()); /* () intializer clears the memory to zero */
if (!this->dram_ptr) {
ABORT_F("%s: could not allocate RAM storage", this->name.c_str());
}
}
if (!add_ram_region(0x00000000, total_ram)) {
ABORT_F("%s: could not allocate RAM storage", this->name.c_str());
ram_map.erase(std::remove_if(ram_map.begin(), ram_map.end(),
[this](AddressMapEntry *entry) {
delete this->remove_region(entry);
return true;
}
), ram_map.end());
uint32_t ram_offset = 0;
uint32_t ram_end = 0;
while (1) {
// find first bank that exists after the last added region
uint32_t ram_start = -1;
for (int bank = 0; bank < 8; bank++) {
if (
this->bank_size[bank] && // has size
this->bank_base[bank] >= ram_end && // starts after the last ending
this->bank_base[bank] < ram_start // has earlier start
) {
ram_start = this->bank_base[bank];
}
}
if (ram_start + 1 == 0)
break;
ram_end = ram_start;
// find the max size of this region
for (int bank = 0; bank < 8; bank++) {
if (
this->bank_size[bank] && // has size
this->bank_base[bank] <= ram_end && // starts before the end
this->bank_base[bank] + this->bank_size[bank] > ram_end // ends after the end
) {
ram_end = this->bank_base[bank] + this->bank_size[bank];
}
}
AddressMapEntry *entry = this->add_ram_region(ram_start, ram_end - ram_start, &dram_ptr[ram_offset]);
if (entry) {
ram_map.push_back(entry);
} else {
ABORT_F("%s: could not allocate RAM storage", this->name.c_str());
}
ram_offset += ram_end - ram_start;
}
}
@@ -420,7 +463,7 @@ void PlatinumCtrl::enable_display() {
bool did_size_change = false;
bool did_refresh_rate_change = false;
bool did_depth_change = false;
int clock_divisor = this->dacula->get_clock_div();
this->pixel_clock = this->dacula->get_dot_freq();
@@ -458,6 +501,9 @@ void PlatinumCtrl::enable_display() {
// set framebuffer parameters
this->fb_ptr = &this->vram_ptr[this->fb_offset] + 16;
this->fb_pitch = this->row_words;
if (this->fb_config_1 & CFG1_INTERLACE) {
this->fb_pitch >>= 1;
}
int new_pixel_depth = this->dacula->get_pix_width();
if (new_pixel_depth != this->pixel_depth)
@@ -497,10 +543,14 @@ void PlatinumCtrl::enable_display() {
}
float new_refresh_rate = (double)(this->pixel_clock) / (this->hori_total * this->vert_total);
if (this->fb_config_1 & CFG1_INTERLACE) {
new_refresh_rate *= 2;
}
if (new_refresh_rate != this->refresh_rate)
did_refresh_rate_change = true;
this->refresh_rate = new_refresh_rate;
this->start_refresh_task();
if (did_size_change)
+2
View File
@@ -368,6 +368,8 @@ private:
std::unique_ptr<uint8_t[]> vram_ptr = nullptr;
std::unique_ptr<DisplayID> display_id = nullptr;
std::unique_ptr<AppleRamdac> dacula = nullptr;
std::unique_ptr<uint8_t[]> dram_ptr = nullptr;
std::vector<AddressMapEntry*> ram_map;
};
#endif // PLATINUM_MEMCTRL_H
+15
View File
@@ -70,6 +70,16 @@ public:
void set_capacity(int capacity_megs) {
switch (capacity_megs) {
case 8:
this->eeprom_data[3] = 0xC; /* 12 rows */
this->eeprom_data[4] = 0x6; /* 6 columns */
this->eeprom_data[5] = 0x1; /* one bank */
break;
case 16:
this->eeprom_data[3] = 0xC; /* 12 rows */
this->eeprom_data[4] = 0x7; /* 7 columns */
this->eeprom_data[5] = 0x1; /* one bank */
break;
case 32:
this->eeprom_data[3] = 0xC; /* 12 rows */
this->eeprom_data[4] = 0x8; /* 8 columns */
@@ -90,6 +100,11 @@ public:
this->eeprom_data[4] = 0xA; /* 10 columns */
this->eeprom_data[5] = 0x2; /* two banks */
break;
case 512:
this->eeprom_data[3] = 0xC; /* 12 rows */
this->eeprom_data[4] = 0xB; /* 11 columns */
this->eeprom_data[5] = 0x2; /* two banks */
break;
default:
throw std::invalid_argument(std::string("Unsupported capacity!"));
}
+4 -4
View File
@@ -104,7 +104,7 @@ enum {
what it actually means. It seems like it's used to check
if the sound codec is available.
*/
#define AWAC_AVAILABLE 0x40
constexpr auto AWAC_AVAILABLE = 0x40;
/** Audio processor chip (TDA7433) emulation. */
@@ -166,9 +166,9 @@ public:
};
/** AWACs manufacturers and revisions. */
#define AWAC_MAKER_CRYSTAL 1
#define AWAC_REV_AWACS 2
#define AWAC_REV_SCREAMER 3
constexpr auto AWAC_MAKER_CRYSTAL = 1;
constexpr auto AWAC_REV_AWACS = 2;
constexpr auto AWAC_REV_SCREAMER = 3;
/** Screamer sound codec. */
class AwacsScreamer : public MacioSndCodec {
+1 -1
View File
@@ -76,7 +76,7 @@ int BlockStorageDevice::set_block_size(const int blk_size) {
}
int BlockStorageDevice::set_fpos(const uint32_t lba) {
this->cur_fpos = lba * this->raw_blk_size;
this->cur_fpos = (uint64_t)lba * (uint64_t)this->raw_blk_size;
return 0;
}
+19 -4
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -77,10 +77,15 @@ static char cdrom_product_id[] = "DINGUS CD-ROM ";
static char cdrom_revision_id[] = "1.0 ";
uint32_t CdromDrive::inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr) {
uint8_t alloc_len = cmd_ptr[4];
int page_num = cmd_ptr[2];
int alloc_len = cmd_ptr[4];
if (page_num) {
ABORT_F("%s: invalid page number in INQUIRY", "CdromDrive");
}
if (alloc_len > 36) {
LOG_F(WARNING, "CD-ROM: more than 36 bytes requested in INQUIRY");
LOG_F(WARNING, "%s: more than 36 bytes requested in INQUIRY", "CdromDrive");
}
data_ptr[0] = 5; // device type: CD-ROM
@@ -94,8 +99,18 @@ uint32_t CdromDrive::inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr) {
std::memcpy(&data_ptr[8], cdrom_vendor_dingus_id, 8);
std::memcpy(&data_ptr[16], cdrom_product_id, 16);
std::memcpy(&data_ptr[32], cdrom_revision_id, 4);
//std::memcpy(&data_ptr[36], serial_number, 8);
//etc.
return 36;
if (alloc_len < 36) {
LOG_F(ERROR, "%s: allocation length too small: %d", "CdromDrive",
alloc_len);
}
else {
memset(&data_ptr[36], 0, alloc_len - 36);
}
return alloc_len;
}
uint32_t CdromDrive::mode_sense_ex(bool is_sense_6, uint8_t* cmd_ptr, uint8_t* data_ptr) {
+185 -24
View File
@@ -34,6 +34,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string>
namespace loguru {
enum : Verbosity {
Verbosity_ATIMACH64 = loguru::Verbosity_9,
Verbosity_ATIINTERRUPT = loguru::Verbosity_9,
Verbosity_ATICURSOR = loguru::Verbosity_9
};
}
/* Human readable Mach64 HW register names for easier debugging. */
static const std::map<uint16_t, std::string> mach64_reg_names = {
#define one_reg_name(x) {ATI_ ## x, #x}
@@ -107,6 +115,19 @@ static const std::map<uint16_t, std::string> mach64_reg_names = {
};
static const std::map<uint16_t, std::string> rgb514_reg_names = {
#define one_reg_name(x) {Rgb514::x, #x}
one_reg_name(CLUT_ADDR_WR),
one_reg_name(CLUT_DATA),
one_reg_name(CLUT_MASK),
one_reg_name(CLUT_ADDR_RD),
one_reg_name(INDEX_LOW),
one_reg_name(INDEX_HIGH),
one_reg_name(INDEX_DATA),
one_reg_name(INDEX_CNTL),
#undef one_reg_name
};
static const std::map<uint16_t, std::string> rgb514_ind_reg_names = {
#define one_reg_name(x) {Rgb514::x, #x}
one_reg_name(MISC_CLK_CNTL),
one_reg_name(HOR_SYNC_POS),
@@ -269,7 +290,7 @@ bool AtiMach64Gx::io_access_allowed(uint32_t offset) {
if (this->command & 1) {
return true;
}
LOG_F(WARNING, "ATI I/O space disabled in the command reg");
LOG_F(WARNING, "%s: I/O space disabled in the command reg", this->name.c_str());
}
return false;
}
@@ -288,6 +309,8 @@ bool AtiMach64Gx::pci_io_read(uint32_t offset, uint32_t size, uint32_t* res)
// CONFIG_CNTL is accessible from I/O space only
if ((offset >> 2) == ATI_CONFIG_CNTL) {
result = read_mem(((uint8_t *)&this->config_cntl) + (offset & 3), size);
LOG_F(ATIMACH64, "%s: read %s %04x.%c = %0*x", this->name.c_str(),
get_reg_name(offset >> 2), offset, SIZE_ARG(size), size * 2, (uint32_t)result);
} else {
result = BYTESWAP_SIZED(this->read_reg(offset, size), size);
}
@@ -348,12 +371,24 @@ const char* AtiMach64Gx::get_reg_name(uint32_t reg_num) {
}
}
static int64_t last_int_cntl_val = -1;
static int64_t int_cntl_count = 1;
uint32_t AtiMach64Gx::read_reg(uint32_t reg_offset, uint32_t size)
{
uint32_t reg_num = reg_offset >> 2;
uint32_t offset = reg_offset & 3;
uint64_t result = this->regs[reg_num];
switch (reg_num) {
case ATI_DAC_REGS:
if (size == 1) { // only byte accesses are allowed for DAC registers
int dac_reg_addr = ((this->regs[ATI_DAC_CNTL] & 1) << 2) | offset;
insert_bits<uint64_t>(result, rgb514_read_reg(dac_reg_addr), 0, 8);
}
break;
}
if (offset || size != 4) { // slow path
if ((offset + size) > 4) {
result |= (uint64_t)(this->regs[reg_num + 1]) << 32;
@@ -361,13 +396,33 @@ uint32_t AtiMach64Gx::read_reg(uint32_t reg_offset, uint32_t size)
result = extract_bits<uint64_t>(result, offset * 8, size * 8);
}
if (reg_num == ATI_CRTC_INT_CNTL) {
int64_t int_cntl_val = result;
if (int_cntl_val == last_int_cntl_val)
int_cntl_count++;
else {
if (int_cntl_count > 1)
LOG_F(ATIINTERRUPT, "%s: read %s %04x.%c = %0*x (%lld times)", this->name.c_str(),
get_reg_name(reg_num), reg_offset, SIZE_ARG(size), size * 2, (uint32_t)last_int_cntl_val, int_cntl_count);
LOG_F(ATIINTERRUPT, "%s: read %s %04x.%c = %0*x", this->name.c_str(),
get_reg_name(reg_num), reg_offset, SIZE_ARG(size), size * 2, (uint32_t)result);
int_cntl_count = 1;
last_int_cntl_val = int_cntl_val;
}
}
else {
last_int_cntl_val = -1;
LOG_F(ATIMACH64, "%s: read %s %04x.%c = %0*x", this->name.c_str(),
get_reg_name(reg_num), reg_offset, SIZE_ARG(size), size * 2, (uint32_t)result);
}
return static_cast<uint32_t>(result);
}
#define WRITE_VALUE_AND_LOG() \
#define WRITE_VALUE_AND_LOG(level) \
do { \
this->regs[reg_num] = new_value; \
LOG_F(9, "%s: write %s %04x.%c = %0*x = %08x", this->name.c_str(), \
LOG_F(level, "%s: write %s %04x.%c = %0*x = %08x", this->name.c_str(), \
get_reg_name(reg_num), reg_offset, SIZE_ARG(size), size * 2, \
(uint32_t)extract_bits<uint64_t>(value, offset * 8, size * 8), new_value \
); \
@@ -392,7 +447,6 @@ void AtiMach64Gx::write_reg(uint32_t reg_offset, uint32_t value, uint32_t size)
switch (reg_num) {
case ATI_CRTC_H_TOTAL_DISP:
new_value = value;
LOG_F(9, "%s: ATI_CRTC_H_TOTAL_DISP set to 0x%08X", this->name.c_str(), value);
break;
case ATI_CRTC_VLINE_CRNT_VLINE:
new_value = old_value;
@@ -400,7 +454,7 @@ void AtiMach64Gx::write_reg(uint32_t reg_offset, uint32_t value, uint32_t size)
break;
case ATI_CRTC_OFF_PITCH:
new_value = value;
WRITE_VALUE_AND_LOG();
WRITE_VALUE_AND_LOG(ATIMACH64);
this->crtc_update();
return;
case ATI_CRTC_INT_CNTL:
@@ -470,7 +524,8 @@ void AtiMach64Gx::write_reg(uint32_t reg_offset, uint32_t value, uint32_t size)
bits_read_only |= bits_not_AKed; // the not AKed bits will remain unchanged
new_value = (old_value & bits_read_only) | (new_value & ~bits_read_only);
break;
WRITE_VALUE_AND_LOG(ATIINTERRUPT);
return;
}
case ATI_CRTC_GEN_CNTL:
{
@@ -498,8 +553,6 @@ void AtiMach64Gx::write_reg(uint32_t reg_offset, uint32_t value, uint32_t size)
new_value = (old_value & bits_read_only) | (new_value & ~bits_read_only);
this->regs[reg_num] = new_value;
if (bit_changed(old_value, new_value, ATI_CRTC_DISPLAY_DIS)) {
if (bit_set(new_value, ATI_CRTC_DISPLAY_DIS)) {
this->blank_on = true;
@@ -509,17 +562,19 @@ void AtiMach64Gx::write_reg(uint32_t reg_offset, uint32_t value, uint32_t size)
}
}
WRITE_VALUE_AND_LOG(ATIMACH64);
if (bit_changed(old_value, new_value, ATI_CRTC_ENABLE)) {
draw_fb = true;
this->crtc_update();
}
break;
return;
}
case ATI_OVR_CLR:
case ATI_OVR_WID_LEFT_RIGHT:
case ATI_OVR_WID_TOP_BOTTOM:
new_value = value;
WRITE_VALUE_AND_LOG();
WRITE_VALUE_AND_LOG(ATIMACH64);
if (value != 0) {
LOG_F(ERROR, "%s: Unhandled value 0x%08x.", this->name.c_str(), value);
}
@@ -529,14 +584,14 @@ void AtiMach64Gx::write_reg(uint32_t reg_offset, uint32_t value, uint32_t size)
new_value = value;
this->cursor_dirty = true;
draw_fb = true;
WRITE_VALUE_AND_LOG();
WRITE_VALUE_AND_LOG(ATICURSOR);
return;
case ATI_CUR_OFFSET:
new_value = value;
if (old_value != new_value)
this->cursor_dirty = true;
draw_fb = true;
WRITE_VALUE_AND_LOG();
WRITE_VALUE_AND_LOG(ATICURSOR);
return;
case ATI_CUR_HORZ_VERT_OFF:
new_value = value;
@@ -546,20 +601,21 @@ void AtiMach64Gx::write_reg(uint32_t reg_offset, uint32_t value, uint32_t size)
)
this->cursor_dirty = true;
draw_fb = true;
WRITE_VALUE_AND_LOG();
WRITE_VALUE_AND_LOG(ATICURSOR);
return;
case ATI_CUR_HORZ_VERT_POSN:
new_value = value;
draw_fb = true;
WRITE_VALUE_AND_LOG();
WRITE_VALUE_AND_LOG(ATICURSOR);
return;
case ATI_DAC_REGS:
new_value = old_value; // no change
WRITE_VALUE_AND_LOG(ATIMACH64);
if (size == 1) { // only byte accesses are allowed for DAC registers
int dac_reg_addr = ((this->regs[ATI_DAC_CNTL] & 1) << 2) | offset;
rgb514_write_reg(dac_reg_addr, extract_bits<uint32_t>(value, offset * 8, 8));
}
break;
return;
case ATI_DAC_CNTL:
new_value = value;
// monitor ID is usually accessed using 8bit writes
@@ -581,7 +637,7 @@ void AtiMach64Gx::write_reg(uint32_t reg_offset, uint32_t value, uint32_t size)
break;
}
this->regs[reg_num] = new_value;
WRITE_VALUE_AND_LOG(ATIMACH64);
}
uint32_t AtiMach64Gx::read(uint32_t rgn_start, uint32_t offset, int size)
@@ -593,6 +649,7 @@ uint32_t AtiMach64Gx::read(uint32_t rgn_start, uint32_t offset, int size)
if (offset >= this->mm_regs_offset && offset < this->mm_regs_offset + 0x400) {
return BYTESWAP_SIZED(read_reg(offset - this->mm_regs_offset, size), size);
}
LOG_F(WARNING, "%s: read unmapped aperture[0] region %08x.%c", this->name.c_str(), offset, SIZE_ARG(size));
return 0;
}
@@ -600,9 +657,11 @@ uint32_t AtiMach64Gx::read(uint32_t rgn_start, uint32_t offset, int size)
if (rgn_start == this->exp_rom_addr) {
if (offset < this->exp_rom_size)
return read_mem(&this->exp_rom_data[offset], size);
LOG_F(WARNING, "%s: read unmapped ROM region %08x.%c", this->name.c_str(), offset, SIZE_ARG(size));
return 0;
}
LOG_F(WARNING, "%s: read unmapped aperture region %08x.%c", this->name.c_str(), offset, SIZE_ARG(size));
return 0;
}
@@ -616,8 +675,12 @@ void AtiMach64Gx::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int
if (offset >= this->mm_regs_offset && offset < this->mm_regs_offset + 0x400) {
return write_reg(offset - this->mm_regs_offset, BYTESWAP_SIZED(value, size), size);
}
LOG_F(WARNING, "%s: write unmapped aperture[0] region %08x.%c = %0*x",
this->name.c_str(), offset, SIZE_ARG(size), size * 2, value);
return;
}
LOG_F(WARNING, "%s: write unmapped aperture region %08x.%c = %0*x",
this->name.c_str(), offset, SIZE_ARG(size), size * 2, value);
}
void AtiMach64Gx::verbose_pixel_format(int crtc_index) {
@@ -703,8 +766,13 @@ void AtiMach64Gx::crtc_update()
static uint8_t bits_per_pixel[8] = {0, 0, 4, 8, 16, 24, 32, 0};
int new_fb_pitch = extract_bits<uint32_t>(this->regs[ATI_CRTC_OFF_PITCH],
ATI_CRTC_PITCH, ATI_CRTC_PITCH_size) * bits_per_pixel[this->pixel_format];
int new_fb_pitch_reg = extract_bits<uint32_t>(this->regs[ATI_CRTC_OFF_PITCH],
ATI_CRTC_PITCH, ATI_CRTC_PITCH_size);
// HACK: should not be zero!
if (new_fb_pitch_reg == 0) {
new_fb_pitch_reg = active_width / 8; // "Display pitch in pixels * 8"
}
int new_fb_pitch = new_fb_pitch_reg * bits_per_pixel[this->pixel_format];
if (new_fb_pitch != this->fb_pitch) {
this->fb_pitch = new_fb_pitch;
need_recalc = true;
@@ -776,6 +844,16 @@ void AtiMach64Gx::crtc_update()
LOG_F(ERROR, "%s: unsupported pixel format %d", this->name.c_str(), this->pixel_format);
}
LOG_F(INFO, "%s: primary CRT controller enabled:", this->name.c_str());
LOG_F(INFO, "Video mode: %s",
bit_set(this->regs[ATI_CRTC_GEN_CNTL], ATI_CRTC_EXT_DISP_EN) ? "extended" : "VGA");
LOG_F(INFO, "Video width: %d px", this->active_width);
LOG_F(INFO, "Video height: %d px", this->active_height);
LOG_F(INFO, "Vertical blank: %d px", this->vert_blank);
verbose_pixel_format(0);
LOG_F(INFO, "Pixel (dot) clock: %f MHz", this->pixel_clock * 1e-6);
LOG_F(INFO, "Refresh rate: %f Hz", this->refresh_rate);
this->stop_refresh_task();
this->start_refresh_task();
@@ -845,7 +923,7 @@ int AtiMach64Gx::device_postinit()
#endif
0;
LOG_F(WARNING, "%s: irq_line_state:%d do_interrupt:%d CRTC_INT_CNTL:%08x",
LOG_F(ATIINTERRUPT, "%s: irq_line_state:%d do_interrupt:%d CRTC_INT_CNTL:%08x",
this->name.c_str(), irq_line_state, do_interrupt,
this->regs[ATI_CRTC_INT_CNTL]);
@@ -857,14 +935,79 @@ int AtiMach64Gx::device_postinit()
}
// ========================== IBM RGB514 related code ==========================
const char* AtiMach64Gx::rgb514_get_reg_name(uint32_t reg_addr)
{
auto iter = rgb514_reg_names.find(reg_addr);
if (iter != rgb514_reg_names.end()) {
return iter->second.c_str();
} else {
return "unknown rgb514 register";
}
}
uint8_t AtiMach64Gx::rgb514_read_reg(uint8_t reg_addr)
{
uint8_t value;
switch (reg_addr) {
case Rgb514::CLUT_ADDR_WR:
value = this->clut_index;
break;
case Rgb514::CLUT_DATA:
if (!this->comp_index_rd) {
uint8_t alpha; // temp variable for unused alpha
get_palette_color(this->clut_index_rd, this->clut_color_rd[0],
this->clut_color_rd[1], this->clut_color_rd[2], alpha);
}
value = this->clut_color_rd[this->comp_index_rd];
LOG_F(ATIMACH64, "%s.rgb514: read CLUT_DATA [%02x].%c = %02x",
this->name.c_str(), this->clut_index, "rgb"[comp_index], value);
if (++this->comp_index_rd >= 3) {
this->clut_index_rd++; // auto-increment reading index
this->comp_index_rd = 0; // reset color component index
}
return value;
case Rgb514::CLUT_MASK:
value = 0xFF;
break;
case Rgb514::CLUT_ADDR_RD:
value = this->clut_index_rd;
break;
case Rgb514::INDEX_LOW:
value = this->dac_idx_lo;
break;
case Rgb514::INDEX_HIGH:
value = this->dac_idx_hi;
break;
case Rgb514::INDEX_DATA:
value = this->rgb514_read_ind_reg((this->dac_idx_hi << 8) + this->dac_idx_lo);
break;
default:
value = 0;
LOG_F(ERROR, "%s.rgb514: read %s %04x.b = %02x", this->name.c_str(),
rgb514_get_reg_name(reg_addr), reg_addr, value
);
}
LOG_F(ATIMACH64, "%s.rgb514: read %s %04x.b = %02x", this->name.c_str(),
rgb514_get_reg_name(reg_addr), reg_addr, value
);
return value;
}
void AtiMach64Gx::rgb514_write_reg(uint8_t reg_addr, uint8_t value)
{
LOG_F(ATIMACH64, "%s.rgb514: write %s %04x.b = %02x", this->name.c_str(),
rgb514_get_reg_name(reg_addr), reg_addr, value
);
switch (reg_addr) {
case Rgb514::CLUT_ADDR_WR:
this->clut_index = value;
this->comp_index = 0;
break;
case Rgb514::CLUT_DATA:
LOG_F(ATIMACH64, "%s.rgb514: write CLUT_DATA [%02x].%c = %02x",
this->name.c_str(), this->clut_index, "rgb"[comp_index], value);
this->clut_color[this->comp_index++] = value;
if (this->comp_index >= 3) {
this->set_palette_color(this->clut_index, clut_color[0],
@@ -879,6 +1022,10 @@ void AtiMach64Gx::rgb514_write_reg(uint8_t reg_addr, uint8_t value)
LOG_F(WARNING, "RGB514: pixel mask set to 0x%X", value);
}
break;
case Rgb514::CLUT_ADDR_RD:
this->clut_index_rd = value;
this->comp_index_rd = 0;
break;
case Rgb514::INDEX_LOW:
this->dac_idx_lo = value;
break;
@@ -889,23 +1036,37 @@ void AtiMach64Gx::rgb514_write_reg(uint8_t reg_addr, uint8_t value)
this->rgb514_write_ind_reg((this->dac_idx_hi << 8) + this->dac_idx_lo, value);
break;
default:
ABORT_F("RGB514: access to unimplemented register at 0x%X", reg_addr);
LOG_F(ERROR, "%s.rgb514: write %s %04x.b = %02x", this->name.c_str(),
rgb514_get_reg_name(reg_addr), reg_addr, value
);
}
}
const char* AtiMach64Gx::rgb514_get_reg_name(uint32_t reg_addr)
const char* AtiMach64Gx::rgb514_get_ind_reg_name(uint32_t reg_addr)
{
auto iter = rgb514_reg_names.find(reg_addr);
if (iter != rgb514_reg_names.end()) {
auto iter = rgb514_ind_reg_names.find(reg_addr);
if (iter != rgb514_ind_reg_names.end()) {
return iter->second.c_str();
} else {
return "unknown rgb514 register";
return "unknown indirect rgb514 register";
}
}
uint8_t AtiMach64Gx::rgb514_read_ind_reg(uint8_t reg_addr)
{
uint8_t value = this->dac_regs[reg_addr];
LOG_F(ATIMACH64, "%s.rgb514: read %s %04x.b = %02x", this->name.c_str(),
rgb514_get_ind_reg_name(reg_addr), reg_addr, value
);
return value;
}
void AtiMach64Gx::rgb514_write_ind_reg(uint8_t reg_addr, uint8_t value)
{
this->dac_regs[reg_addr] = value;
LOG_F(ATIMACH64, "%s.rgb514: write %s %04x.b = %02x", this->name.c_str(),
rgb514_get_ind_reg_name(reg_addr), reg_addr, value
);
switch (reg_addr) {
case Rgb514::MISC_CLK_CNTL:
+9
View File
@@ -61,11 +61,14 @@ protected:
void notify_bar_change(int bar_num);
const char* get_reg_name(uint32_t reg_offset);
const char* rgb514_get_reg_name(uint32_t reg_offset);
const char* rgb514_get_ind_reg_name(uint32_t reg_offset);
bool io_access_allowed(uint32_t offset);
uint32_t read_reg(uint32_t reg_offset, uint32_t size);
void write_reg(uint32_t reg_offset, uint32_t value, uint32_t size);
void crtc_update();
uint8_t rgb514_read_reg(uint8_t reg_addr);
void rgb514_write_reg(uint8_t reg_addr, uint8_t value);
uint8_t rgb514_read_ind_reg(uint8_t reg_addr);
void rgb514_write_ind_reg(uint8_t reg_addr, uint8_t value);
void verbose_pixel_format(int crtc_index);
void draw_hw_cursor(uint8_t *dst_buf, int dst_pitch);
@@ -90,9 +93,15 @@ private:
// RGB514 RAMDAC state
uint8_t dac_idx_lo = 0;
uint8_t dac_idx_hi = 0;
uint8_t clut_index = 0;
uint8_t comp_index = 0;
uint8_t clut_color[3] = {0};
uint8_t clut_index_rd = 0;
uint8_t comp_index_rd = 0;
uint8_t clut_color_rd[3] = {0};
uint8_t dac_regs[256] = {0};
std::unique_ptr<DisplayID> disp_id;
+54 -6
View File
@@ -96,6 +96,7 @@ ATIRage::ATIRage(uint16_t dev_id)
supports_types(HWCompType::MMIO_DEV | HWCompType::PCI_DEV);
this->vram_size = GET_INT_PROP("gfxmem_size") << 20; // convert MBs to bytes
this->framebuffer_size = std::min(this->vram_size, ((uint32_t)8 << 20) - 0x800);
// allocate video RAM
this->vram_ptr = std::unique_ptr<uint8_t[]> (new uint8_t[this->vram_size]);
@@ -263,7 +264,32 @@ uint32_t ATIRage::read_reg(uint32_t reg_offset, uint32_t size) {
}
break;
case ATI_GUI_STAT:
result = this->cmd_fifo_size << 16; // HACK: tell the guest the command FIFO is empty
result = uint64_t(this->cmd_fifo_size << 16); // HACK: tell the guest the command FIFO is empty
break;
case ATI_DP_BKGD_CLR:
case ATI_DP_FRGD_CLR:
uint32_t pix_fmt = extract_bits<uint32_t>(
this->regs[ATI_CRTC_GEN_CNTL], ATI_CRTC_PIX_WIDTH, ATI_CRTC_PIX_WIDTH_size);
switch (pix_fmt) {
case 1:
result = result & 0x1;
break;
case 2:
result = result & 0xFF;
break;
case 3:
case 4:
result = result & 0xFFFF;
break;
case 5:
result = result & 0xFFFFFF;
break;
case 6:
break;
default:
LOG_F(ERROR, "Incorrect bit depth");
}
break;
}
@@ -534,6 +560,28 @@ void ATIRage::write_reg(uint32_t reg_offset, uint32_t value, uint32_t size) {
new_value = (old_value & bits_read_only) | (new_value & ~bits_read_only);
break;
}
case ATI_DST_WIDTH:
new_value = value & 0x7FFF;
this->regs[ATI_DST_BRES_LNTH] = new_value;
break;
case ATI_DST_HEIGHT:
new_value = value & 0x7FFF;
this->regs[ATI_DST_BRES_LNTH] = new_value;
break;
case ATI_DST_BRES_ERR:
new_value = value & 0x3FFFF;
if (new_value > -1) {
new_value += this->regs[ATI_DST_BRES_INC];
} else {
new_value += this->regs[ATI_DST_BRES_DEC];
}
break;
case ATI_DST_BRES_INC:
new_value = value & 0x3FFFF;
break;
case ATI_DST_BRES_DEC:
new_value = -(value & 0x3FFFF);
break;
default:
new_value = value;
break;
@@ -573,11 +621,11 @@ bool ATIRage::pci_io_write(uint32_t offset, uint32_t value, uint32_t size) {
uint32_t ATIRage::read(uint32_t rgn_start, uint32_t offset, int size)
{
if (rgn_start == this->aperture_base[0] && offset < this->aperture_size[0]) {
if (offset < this->vram_size) { // little-endian VRAM region
if (offset < this->framebuffer_size) { // little-endian VRAM region
return read_mem(&this->vram_ptr[offset], size);
}
if (offset >= BE_FB_OFFSET) { // big-endian VRAM region
return read_mem(&this->vram_ptr[offset - BE_FB_OFFSET], size);
return read_mem(&this->vram_ptr[uint64_t(offset) - BE_FB_OFFSET], size);
}
//if (!bit_set(this->regs[ATI_BUS_CNTL], ATI_BUS_APER_REG_DIS)) {
if (offset >= MM_REGS_0_OFF) { // memory-mapped registers, block 0
@@ -617,7 +665,7 @@ uint32_t ATIRage::read(uint32_t rgn_start, uint32_t offset, int size)
void ATIRage::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
{
if (rgn_start == this->aperture_base[0] && offset < this->aperture_size[0]) {
if (offset < this->vram_size) { // little-endian VRAM region
if (offset < this->framebuffer_size) { // little-endian VRAM region
draw_fb = true;
return write_mem(&this->vram_ptr[offset], value, size);
}
@@ -651,7 +699,7 @@ void ATIRage::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int siz
this->name.c_str(), offset, SIZE_ARG(size), size * 2, value);
}
float ATIRage::calc_pll_freq(int scale, int fb_div) {
float ATIRage::calc_pll_freq(int scale, int fb_div) const {
return (ATI_XTAL * scale * fb_div) / this->plls[PLL_REF_DIV];
}
@@ -931,7 +979,7 @@ int ATIRage::device_postinit()
static const PropMap AtiRage_Properties = {
{"gfxmem_size",
new IntProperty( 2, std::vector<uint32_t>({2, 4, 6}))},
new IntProperty(2, std::vector<uint32_t>({2, 4, 6, 8}))},
{"mon_id",
new StrProperty("")},
};
+2 -1
View File
@@ -76,7 +76,7 @@ protected:
bool io_access_allowed(uint32_t offset);
uint32_t read_reg(uint32_t reg_offset, uint32_t size);
void write_reg(uint32_t reg_addr, uint32_t value, uint32_t size);
float calc_pll_freq(int scale, int fb_div);
float calc_pll_freq(int scale, int fb_div) const;
void verbose_pixel_format(int crtc_index);
void crtc_update();
void draw_hw_cursor(uint8_t *dst_buf, int dst_pitch);
@@ -94,6 +94,7 @@ private:
// Video RAM variables
std::unique_ptr<uint8_t[]> vram_ptr;
uint32_t vram_size;
uint32_t framebuffer_size;
// config 0x40
uint8_t user_cfg = 8;
+26 -1
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -29,15 +29,33 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <functional>
#include <memory>
class VideoCtrlBase;
class Display {
public:
enum {
not_full_screen,
full_screen_small,
full_screen_int,
full_screen,
full_screen_no_bars,
};
Display();
~Display();
void set_video_ctrl(VideoCtrlBase* video_ctrl) {
this->video_ctrl = video_ctrl;
}
// Configures the display for the given width/height.
// Returns true if this is the first time the screen has been configured.
bool configure(int width, int height);
void configure_dest();
void configure_texture();
void update_window_size();
// Clears the display
void blank();
@@ -58,9 +76,16 @@ public:
void handle_events(const WindowEvent& wnd_event);
void setup_hw_cursor(std::function<void(uint8_t *dst_buf, int dst_pitch)> draw_hw_cursor,
int cursor_width, int cursor_height);
void update_window_title();
void toggle_mouse_grab();
void update_mouse_grab(bool will_be_grabbed);
private:
class Impl; // Holds private fields
std::unique_ptr<Impl> impl;
VideoCtrlBase* video_ctrl = nullptr;
int full_screen_mode = not_full_screen;
double scale_full_screen;
double scale_window;
};
#endif // DISPLAY_H
+263 -35
View File
@@ -20,20 +20,29 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <devices/video/display.h>
#include <devices/video/videoctrl.h>
#include <SDL.h>
#include <loguru.hpp>
#include <cmath>
#include <string>
class Display::Impl {
public:
bool resizing = false;
uint32_t disp_wnd_id = 0;
SDL_Window* display_wnd = 0;
SDL_Renderer* renderer = 0;
double renderer_scale_x; // scaling factor from guest OS to host OS
double renderer_scale_y;
double default_scale_x;
double default_scale_y;
SDL_Texture* disp_texture = 0;
SDL_Texture* cursor_texture = 0;
SDL_Rect cursor_rect; // destination rectangle for cursor drawing
int display_w;
int display_h;
double drawable_w;
double drawable_h;
SDL_Rect dest_rect;
};
Display::Display(): impl(std::make_unique<Impl>()) {
@@ -57,13 +66,15 @@ Display::~Display() {
bool Display::configure(int width, int height) {
bool is_initialization = false;
impl->display_w = width;
impl->display_h = height;
if (!impl->display_wnd) { // create display window
impl->display_wnd = SDL_CreateWindow(
SDL_GetRelativeMouseMode() ?
"DingusPPC Display (Mouse Grabbed)" : "DingusPPC Display",
"",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
width, height,
impl->display_w, impl->display_h,
SDL_WINDOW_OPENGL | SDL_WINDOW_ALLOW_HIGHDPI
);
@@ -75,16 +86,99 @@ bool Display::configure(int width, int height) {
if (impl->renderer == NULL)
ABORT_F("Display: SDL_CreateRenderer failed with %s", SDL_GetError());
int drawable_width, drawable_height;
SDL_GetRendererOutputSize(impl->renderer, &drawable_width, &drawable_height);
impl->renderer_scale_x = static_cast<double>(drawable_width) / width;
impl->renderer_scale_y = static_cast<float>(drawable_height) / height;
SDL_RendererInfo info;
SDL_GetRendererInfo(impl->renderer, &info);
LOG_F(INFO, "Renderer \"%s\" max size: %d x %d", info.name, info.max_texture_width, info.max_texture_height);
int w, h;
SDL_GetRendererOutputSize(impl->renderer, &w, &h);
impl->drawable_w = w;
impl->drawable_h = h;
impl->default_scale_x = impl->drawable_w / impl->display_w;
impl->default_scale_y = impl->drawable_h / impl->display_h;
this->scale_window = impl->default_scale_x;
this->configure_dest();
update_window_title();
is_initialization = true;
} else { // resize display window
SDL_SetWindowSize(impl->display_wnd, width, height);
this->update_window_size();
this->configure_dest();
}
configure_texture();
return is_initialization;
}
void Display::update_window_size() {
impl->drawable_w = this->scale_window * impl->display_w;
impl->drawable_h = this->scale_window * impl->display_h;
SDL_SetWindowSize(impl->display_wnd,
impl->drawable_w / impl->default_scale_x,
impl->drawable_h / impl->default_scale_y);
this->update_mouse_grab(false); // make sure the mouse is still inside the window
}
void Display::configure_dest() {
if (this->full_screen_mode > not_full_screen) {
if (this->scale_full_screen == 0.0) {
int w, h;
SDL_SetWindowFullscreen(impl->display_wnd, SDL_WINDOW_FULLSCREEN_DESKTOP);
SDL_GetRendererOutputSize(impl->renderer, &w, &h);
impl->drawable_w = w;
impl->drawable_h = h;
}
}
double scalex = impl->drawable_w / impl->display_w;
double scaley = impl->drawable_h / impl->display_h;
double scale_full = std::min(scalex, scaley);
double scale_full_int = floor(scale_full);
double scale_full_no_bars = std::max(scalex, scaley);
double scale;
if (this->full_screen_mode > not_full_screen) {
if (this->scale_full_screen == 0.0) {
switch (this->full_screen_mode) {
case full_screen_int:
this->scale_full_screen = scale_full_int;
break;
case full_screen:
this->scale_full_screen = scale_full;
break;
case full_screen_no_bars:
this->scale_full_screen = scale_full_no_bars;
break;
}
}
scale = this->scale_full_screen;
if (scale >= scale_full_no_bars)
this->full_screen_mode = full_screen_no_bars;
else if (scale >= scale_full)
this->full_screen_mode = full_screen;
else if (scale >= scale_full_int)
this->full_screen_mode = full_screen_int;
else
this->full_screen_mode = full_screen_small;
}
else {
scale = this->scale_window = scale_full;
}
LOG_F(INFO, "drawable: %.0f x %.0f display: %d x %d scale: %.3f",
impl->drawable_w, impl->drawable_h, impl->display_w, impl->display_h, scale);
impl->dest_rect.w = std::round(scale * impl->display_w);
impl->dest_rect.h = std::round(scale * impl->display_h);
impl->dest_rect.x = std::round((impl->drawable_w - impl->dest_rect.w) / 2.0),
impl->dest_rect.y = std::round((impl->drawable_h - impl->dest_rect.h) / 2.0),
impl->renderer_scale_x = scale;
impl->renderer_scale_y = scale;
}
void Display::configure_texture() {
if (impl->disp_texture)
SDL_DestroyTexture(impl->disp_texture);
@@ -92,34 +186,171 @@ bool Display::configure(int width, int height) {
impl->renderer,
SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STREAMING,
width, height
impl->display_w, impl->display_h
);
if (impl->disp_texture == NULL)
ABORT_F("Display: SDL_CreateTexture failed with %s", SDL_GetError());
return is_initialization;
}
void Display::handle_events(const WindowEvent& wnd_event) {
if (wnd_event.sub_type == SDL_WINDOWEVENT_SIZE_CHANGED &&
wnd_event.window_id == impl->disp_wnd_id)
impl->resizing = false;
if (wnd_event.sub_type == SDL_WINDOWEVENT_EXPOSED &&
wnd_event.window_id == impl->disp_wnd_id)
SDL_RenderPresent(impl->renderer);
if (wnd_event.sub_type == WINDOW_SCALE_QUALITY_TOGGLE &&
wnd_event.window_id == impl->disp_wnd_id) {
auto current_quality = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
auto new_quality = current_quality == NULL || strcmp(current_quality, "nearest") == 0 ? "best" : "nearest";
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, new_quality);
// We need the window/texture to be recreated to pick up the hint change.
int width, height;
SDL_GetWindowSize(impl->display_wnd, &width, &height);
this->configure(width, height);
switch (wnd_event.sub_type) {
case SDL_WINDOWEVENT_SIZE_CHANGED:
if (wnd_event.window_id == impl->disp_wnd_id) {
int ww, wh;
SDL_GetWindowSize(impl->display_wnd, &ww, &wh);
int w, h;
SDL_GetRendererOutputSize(impl->renderer, &w, &h);
double new_default_scale_x = w / ww;
double new_default_scale_y = w / ww;
if (new_default_scale_x != impl->default_scale_x || new_default_scale_y != impl->default_scale_y) {
// recalculate scale when switching between Retina and Low Resolution modes
impl->drawable_w = impl->drawable_w * new_default_scale_x / impl->default_scale_x;
impl->drawable_h = impl->drawable_h * new_default_scale_y / impl->default_scale_y;
this->scale_window = this->scale_window * new_default_scale_x / impl->default_scale_x;
impl->default_scale_x = new_default_scale_x;
impl->default_scale_y = new_default_scale_y;
this->configure_dest();
}
this->update_window_title();
video_ctrl->set_draw_fb();
}
break;
case SDL_WINDOWEVENT_EXPOSED:
if (wnd_event.window_id == impl->disp_wnd_id) {
SDL_RenderPresent(impl->renderer);
}
break;
case DPPC_WINDOWEVENT_WINDOW_SCALE_QUALITY_TOGGLE:
if (wnd_event.window_id == impl->disp_wnd_id) {
auto current_quality = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
auto new_quality = current_quality == NULL || strcmp(current_quality, "nearest") == 0 ? "best" : "nearest";
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, new_quality);
// We need the window/texture to be recreated to pick up the hint change.
this->configure_texture();
video_ctrl->set_draw_fb();
video_ctrl->set_cursor_dirty();
}
break;
case DPPC_WINDOWEVENT_WINDOW_FULL_SCREEN_TOGGLE:
if (wnd_event.window_id == impl->disp_wnd_id) {
switch (this->full_screen_mode) {
case not_full_screen:
case full_screen_small:
this->full_screen_mode = full_screen_int;
this->scale_full_screen = 0.0;
break;
case full_screen_int:
this->full_screen_mode = full_screen;
this->scale_full_screen = 0.0;
break;
case full_screen:
this->full_screen_mode = full_screen_no_bars;
this->scale_full_screen = 0.0;
break;
case full_screen_no_bars:
SDL_SetWindowFullscreen(impl->display_wnd, 0);
this->full_screen_mode = not_full_screen;
this->update_window_size();
break;
}
this->configure_dest();
video_ctrl->set_draw_fb();
video_ctrl->set_cursor_dirty();
}
break;
case DPPC_WINDOWEVENT_WINDOW_BIGGER:
case DPPC_WINDOWEVENT_WINDOW_SMALLER:
if (wnd_event.window_id == impl->disp_wnd_id) {
if (this->full_screen_mode == not_full_screen) {
if (wnd_event.sub_type == DPPC_WINDOWEVENT_WINDOW_BIGGER)
this->scale_window = this->scale_window * std::pow(2.0, 1.0/8.0);
else
this->scale_window = this->scale_window / std::pow(2.0, 1.0/8.0);
this->update_window_size();
} else {
if (wnd_event.sub_type == DPPC_WINDOWEVENT_WINDOW_BIGGER)
this->scale_full_screen = this->scale_full_screen * std::pow(2.0, 1.0/8.0);
else
this->scale_full_screen = this->scale_full_screen / std::pow(2.0, 1.0/8.0);
}
this->configure_dest();
video_ctrl->set_draw_fb();
video_ctrl->set_cursor_dirty();
}
break;
case DPPC_WINDOWEVENT_MOUSE_GRAB_TOGGLE:
if (wnd_event.window_id == impl->disp_wnd_id)
this->toggle_mouse_grab();
break;
case DPPC_WINDOWEVENT_MOUSE_GRAB_CHANGED:
this->update_window_title();
break;
}
}
void Display::toggle_mouse_grab()
{
if (SDL_GetRelativeMouseMode()) {
SDL_SetRelativeMouseMode(SDL_FALSE);
} else {
this->update_mouse_grab(true);
SDL_SetRelativeMouseMode(SDL_TRUE);
}
}
void Display::update_mouse_grab(bool will_be_grabbed)
{
bool is_grabbed = SDL_GetRelativeMouseMode();
if (will_be_grabbed || is_grabbed) {
// If the mouse is initially outside the window, move it to the middle,
// so that clicks are handled by the window (instead making it lose
// focus, at least with macOS hosts).
int window_x, window_y, window_width, window_height, mouse_x, mouse_y;
SDL_GetWindowPosition(impl->display_wnd, &window_x, &window_y);
SDL_GetWindowSize(impl->display_wnd, &window_width, &window_height);
SDL_GetGlobalMouseState(&mouse_x, &mouse_y);
if (mouse_x < window_x || mouse_x >= window_x + window_width ||
mouse_y < window_y || mouse_y >= window_y + window_height) {
if (is_grabbed)
SDL_SetRelativeMouseMode(SDL_FALSE);
SDL_WarpMouseInWindow(impl->display_wnd, window_width / 2, window_height / 2);
if (is_grabbed)
SDL_SetRelativeMouseMode(SDL_TRUE);
}
}
}
void Display::update_window_title()
{
std::string old_window_title = SDL_GetWindowTitle(impl->display_wnd);
int width, height;
SDL_GetWindowSize(impl->display_wnd, &width, &height);
bool is_grabbed = SDL_GetRelativeMouseMode();
std::string new_window_title = "DingusPPC Display " +
std::to_string(impl->display_w) + "x" + std::to_string(impl->display_h)
+ " " + std::to_string(int(std::round(impl->renderer_scale_x * 100))) + "%";
if (is_grabbed)
new_window_title += " (🖱 Grabbed)";
if (new_window_title != old_window_title)
SDL_SetWindowTitle(impl->display_wnd, new_window_title.c_str());
}
void Display::blank() {
SDL_SetRenderDrawColor(impl->renderer, 0, 0, 0, 255);
SDL_RenderClear(impl->renderer);
@@ -130,10 +361,7 @@ void Display::update(std::function<void(uint8_t *dst_buf, int dst_pitch)> conver
std::function<void(uint8_t *dst_buf, int dst_pitch)> cursor_ovl_cb,
bool draw_hw_cursor, int cursor_x, int cursor_y,
bool fb_known_to_be_changed) {
if (impl->resizing)
return;
uint8_t* dst_buf;
uint8_t* dst_buf = nullptr;
int dst_pitch;
SDL_LockTexture(impl->disp_texture, NULL, (void **)&dst_buf, &dst_pitch);
@@ -147,12 +375,12 @@ void Display::update(std::function<void(uint8_t *dst_buf, int dst_pitch)> conver
SDL_UnlockTexture(impl->disp_texture);
SDL_RenderClear(impl->renderer);
SDL_RenderCopy(impl->renderer, impl->disp_texture, NULL, NULL);
SDL_RenderCopy(impl->renderer, impl->disp_texture, NULL, &impl->dest_rect);
// draw HW cursor if enabled
if (draw_hw_cursor) {
impl->cursor_rect.x = cursor_x * impl->renderer_scale_x;
impl->cursor_rect.y = cursor_y * impl->renderer_scale_y;
impl->cursor_rect.x = cursor_x * impl->renderer_scale_x + impl->dest_rect.x;
impl->cursor_rect.y = cursor_y * impl->renderer_scale_y + impl->dest_rect.y;
SDL_RenderCopy(impl->renderer, impl->cursor_texture, NULL, &impl->cursor_rect);
}
@@ -165,7 +393,7 @@ void Display::update_skipped() {
void Display::setup_hw_cursor(std::function<void(uint8_t *dst_buf, int dst_pitch)> draw_hw_cursor,
int cursor_width, int cursor_height) {
uint8_t* dst_buf;
uint8_t* dst_buf = nullptr;
int dst_pitch;
if (impl->cursor_texture)
+20 -8
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -211,14 +211,8 @@ void PdmOnboardVideo::enable_video_internal()
ABORT_F("PDM-Video: invalid video mode %d", this->video_mode);
}
// figure out where our framebuffer is located
uint64_t hmc_control = this->hmc_obj->get_control_reg();
uint32_t fb_base_phys = ((hmc_control >> HMC_VBASE_BIT) & 1) ? 0 : 0x100000;
LOG_F(INFO, "PDM-Video: framebuffer phys base addr = 0x%X", fb_base_phys);
// set CRTC parameters
MapDmaResult res = mmu_map_dma_mem(fb_base_phys, PDM_FB_SIZE_MAX, false);
this->fb_ptr = res.host_va;
this->set_fb_base();
this->active_width = new_width;
this->active_height = new_height;
this->hori_blank = hori_blank;
@@ -230,6 +224,12 @@ void PdmOnboardVideo::enable_video_internal()
this->stop_refresh_task();
this->vbl_cb = [this](uint8_t irq_line_state) {
this->set_fb_base();
if (this->int_ctrl)
this->int_ctrl->ack_int(this->irq_id, irq_line_state);
};
// set up video refresh timer
this->refresh_rate = (double)(this->pixel_clock) / hori_total / vert_total;
LOG_F(INFO, "PDM-Video: refresh rate set to %f Hz", this->refresh_rate);
@@ -249,6 +249,18 @@ void PdmOnboardVideo::disable_video_internal()
LOG_F(9, "PDM-Video: video disabled");
}
void PdmOnboardVideo::set_fb_base() {
// figure out where our framebuffer is located
uint64_t hmc_control = this->hmc_obj->get_control_reg();
uint8_t vmem_loc = (hmc_control >> HMC_VBASE_BIT) & 1;
if (this->fb_loc != vmem_loc) {
uint32_t fb_base_phys = vmem_loc ? 0 : 0x100000;
MapDmaResult res = mmu_map_dma_mem(fb_base_phys, PDM_FB_SIZE_MAX, false);
this->fb_ptr = res.host_va;
this->fb_loc = vmem_loc;
}
}
/** Ariel II has a weird 1bpp mode where a white pixel is mapped to
CLUT entry #127 (%01111111) and a black pixel to #255 (%11111111).
It requres a non-standard conversion routine implemented below.
+11 -8
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -31,10 +31,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
class HMC;
class InterruptCtrl;
#define PDM_VMODE_OFF 0x1F
constexpr auto PDM_VMODE_OFF = 0x1F;
/** Max. size of our framebuffer in bytes (RGB 13-inch, 16 bpp) */
#define PDM_FB_SIZE_MAX (640 * 480 * 2)
constexpr auto PDM_FB_SIZE_MAX = (640 * 480 * 2);
/** Fixed video modes supported by the PDM on-board video. */
enum PdmVideoMode : uint8_t {
@@ -50,14 +50,14 @@ public:
PdmOnboardVideo();
~PdmOnboardVideo() = default;
uint8_t get_video_mode() {
uint8_t get_video_mode() const {
return ((this->video_mode & 0x1F) | this->blanking);
};
void set_video_mode(uint8_t new_mode);
void set_pixel_depth(uint8_t depth);
void set_vdac_config(uint8_t config);
uint8_t get_vdac_config() {
uint8_t get_vdac_config() const {
return this->vdac_mode;
};
void set_clut_index(uint8_t index);
@@ -69,9 +69,11 @@ public:
};
protected:
void set_depth_internal(int width);
void enable_video_internal();
void disable_video_internal();
void set_depth_internal(int width);
void enable_video_internal();
void disable_video_internal();
void set_fb_base();
void convert_frame_1bpp_indexed(uint8_t *dst_buf, int dst_pitch) override;
void convert_frame_2bpp_indexed(uint8_t *dst_buf, int dst_pitch) override;
void convert_frame_4bpp_indexed(uint8_t *dst_buf, int dst_pitch) override;
@@ -82,6 +84,7 @@ private:
uint8_t vdac_mode;
uint8_t clut_index;
uint8_t comp_index;
uint8_t fb_loc = 0;
uint8_t clut_color[3];
HMC* hmc_obj;
+3 -3
View File
@@ -344,6 +344,9 @@ void Sixty6Video::enable_display()
// get pixel depth
switch (this->pixel_format) {
default:
LOG_F(ERROR, "Sixty6: Invalid pixel format %d!", this->pixel_format);
// fallthrough
case 1:
this->pixel_depth = 8;
this->convert_fb_cb = [this](uint8_t *dst_buf, int dst_pitch) {
@@ -356,9 +359,6 @@ void Sixty6Video::enable_display()
this->convert_frame_15bpp_BE(dst_buf, dst_pitch);
};
break;
default:
LOG_F(ERROR, "Sixty6: Invalid pixel format %d!", this->pixel_format);
// fallthrough
case 3:
this->pixel_depth = 32;
this->convert_fb_cb = [this](uint8_t *dst_buf, int dst_pitch) {
+10 -1
View File
@@ -33,6 +33,7 @@ VideoCtrlBase::VideoCtrlBase(int width, int height)
EventManager::get_instance()->add_window_handler(this, &VideoCtrlBase::handle_events);
this->create_display_window(width, height);
this->display.set_video_ctrl(this);
}
VideoCtrlBase::~VideoCtrlBase()
@@ -74,7 +75,7 @@ void VideoCtrlBase::update_screen()
this->get_cursor_position(cursor_x, cursor_y);
}
if (draw_fb) {
if (this->draw_fb) {
if (this->cursor_dirty) {
this->setup_hw_cursor();
this->cursor_dirty = false;
@@ -88,6 +89,14 @@ void VideoCtrlBase::update_screen()
}
}
void VideoCtrlBase::set_draw_fb() {
this->draw_fb = true;
}
void VideoCtrlBase::set_cursor_dirty() {
this->cursor_dirty = true;
}
void VideoCtrlBase::start_refresh_task() {
this->display.configure(this->active_width, this->active_height);
+3 -1
View File
@@ -41,6 +41,8 @@ public:
void create_display_window(int width, int height);
void blank_display();
void update_screen(void);
void set_draw_fb();
void set_cursor_dirty();
void start_refresh_task();
void stop_refresh_task();
@@ -88,7 +90,7 @@ protected:
float refresh_rate;
// Implementations may choose to track framebuffer writes and set draw_fb
// to false if updates can be skipped. If the do this, they should set
// to false if updates can be skipped. If they do this, they should set
// draw_fb_is_dynamic at initialization time.
bool draw_fb = true;
bool draw_fb_is_dynamic = false;
+47 -19
View File
@@ -30,12 +30,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifdef __GNUG__ /* GCC, ICC and Clang */
# ifdef __APPLE__
# include <machine/endian.h>
# else
# include <endian.h>
# endif
# define BYTESWAP_16(x) (__builtin_bswap16 (x))
# define BYTESWAP_32(x) (__builtin_bswap32 (x))
# define BYTESWAP_64(x) (__builtin_bswap64 (x))
@@ -48,24 +42,58 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
# define BYTESWAP_32(x) (_byteswap_ulong (x))
# define BYTESWAP_64(x) (_byteswap_uint64 (x))
#elif __has_include(<byteswap.h>) /* Many unixes */
# include <byteswap.h>
# define BYTESWAP_16(x) (bswap_16(x))
# define BYTESWAP_32(x) (bswap_32(x))
# define BYTESWAP_64(x) (bswap_64(x))
// TODO: C++23 has std::byteswap
#else
# warning "Unknown byte swapping built-ins (do it the slow way)!"
// #warning is not standard until C++23:
//
// # warning "Unknown byte swapping built-ins (do it the slow way)!"
# define BYTESWAP_16(x) (((x) >> 8) | (((x) & 0xFFUL) << 8))
# include <cstdint>
# define BYTESWAP_32(x) (((x) >> 24) | (((x) >> 8) & 0xFF00UL) | \
(((x) & 0xFF00UL) << 8) | ((x) << 24))
// Most optimizing compilers will translate these functions directly
// into their native instructions (e.g. bswap on x86).
inline std::uint16_t byteswap_16_impl(std::uint16_t x)
{
return (x >> 8) | (x << 8);
}
# define BYTESWAP_64(x) \
(((x) >> 56) | \
(((x) & 0x00FF000000000000ULL) >> 48) | \
(((x) & 0x0000FF0000000000ULL) >> 40) | \
(((x) & 0x000000FF00000000ULL) >> 32) | \
(((x) & 0x00000000FF000000ULL) << 32) | \
(((x) & 0x0000000000FF0000ULL) << 40) | \
(((x) & 0x000000000000FF00ULL) << 48) | \
(((x) & 0x00000000000000FFULL) << 56))
inline std::uint32_t byteswap_32_impl(std::uint32_t x)
{
return (
((x & UINT32_C(0x000000FF)) << 24)
| ((x & UINT32_C(0x0000FF00)) << 8)
| ((x & UINT32_C(0x00FF0000)) >> 8)
| ((x & UINT32_C(0xFF000000)) >> 24)
);
}
inline std::uint64_t byteswap_64_impl(std::uint64_t x)
{
return (
((x & UINT64_C(0x00000000000000FF)) << 56)
| ((x & UINT64_C(0x000000000000FF00)) << 40)
| ((x & UINT64_C(0x0000000000FF0000)) << 24)
| ((x & UINT64_C(0x00000000FF000000)) << 8)
| ((x & UINT64_C(0x000000FF00000000)) >> 8)
| ((x & UINT64_C(0x0000FF0000000000)) >> 24)
| ((x & UINT64_C(0x00FF000000000000)) >> 40)
| ((x & UINT64_C(0xFF00000000000000)) >> 56)
);
}
# define BYTESWAP_16(x) (byteswap_16_impl(x))
# define BYTESWAP_32(x) (byteswap_32_impl(x))
# define BYTESWAP_64(x) (byteswap_64_impl(x))
#endif
+115
View File
@@ -0,0 +1,115 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file Construct the Bondi machine (iMac G3). */
#include <cpu/ppc/ppcemu.h>
#include <devices/ioctrl/macio.h>
#include <devices/memctrl/mpc106.h>
#include <devices/memctrl/spdram.h>
#include <machines/machinebase.h>
#include <machines/machinefactory.h>
#include <machines/machineproperties.h>
static const std::vector<PciIrqMap> grackle_irq_map = {
{nullptr , DEV_FUN(0x00,0), }, // Grackle
{"pci_A1" , DEV_FUN(0x0D,0), IntSrc::PCI_A },
{"pci_B1" , DEV_FUN(0x0E,0), IntSrc::PCI_B },
{"pci_C1" , DEV_FUN(0x0F,0), IntSrc::PCI_C },
{nullptr , DEV_FUN(0x10,0), },
{"pci_GPU" , DEV_FUN(0x12,0), IntSrc::PCI_GPU }, // Heathrow
{"pci_PERCH", DEV_FUN(0x14,0), IntSrc::PCI_PERCH},
};
static void setup_ram_slot(std::string name, int i2c_addr, int capacity_megs) {
if (!capacity_megs)
return;
gMachineObj->add_device(name, std::unique_ptr<SpdSdram168>(new SpdSdram168(i2c_addr)));
SpdSdram168* ram_dimm = dynamic_cast<SpdSdram168*>(gMachineObj->get_comp_by_name(name));
ram_dimm->set_capacity(capacity_megs);
// register RAM DIMM with the I2C bus
I2CBus* i2c_bus = dynamic_cast<I2CBus*>(gMachineObj->get_comp_by_type(HWCompType::I2C_HOST));
i2c_bus->register_device(i2c_addr, ram_dimm);
}
int initialize_bondi(std::string& id) {
LOG_F(INFO, "Building machine Bondi...");
// get pointer to the memory controller/primary PCI bridge object
MPC106* grackle_obj = dynamic_cast<MPC106*>(gMachineObj->get_comp_by_name("Grackle"));
grackle_obj->set_irq_map(grackle_irq_map);
HeathrowIC* heathrow = dynamic_cast<HeathrowIC*>(gMachineObj->get_comp_by_name("Heathrow"));
heathrow->set_media_bay_id(0x30);
grackle_obj->pci_register_device(DEV_FUN(0x10,0), heathrow);
// allocate ROM region
if (!grackle_obj->add_rom_region(0xFFF00000, 0x100000)) {
LOG_F(ERROR, "Could not allocate ROM region!");
return -1;
}
// configure RAM slots
// First ram slot is enumerated twice for some reason, the second slot is never enumerated, so
// make sure both slots have the same RAM.
uint32_t bank_1_size = GET_INT_PROP("rambank1_size");
uint32_t bank_2_size = GET_INT_PROP("rambank2_size");
if (bank_1_size != bank_2_size)
LOG_F(ERROR, "rambank1_size and rambank2_size should have equal size");
setup_ram_slot("RAM_DIMM_1", 0x50, bank_1_size);
setup_ram_slot("RAM_DIMM_2", 0x51, bank_2_size);
// configure CPU clocks
uint64_t bus_freq = 66820000ULL;
uint64_t timebase_freq = bus_freq / 4;
// initialize virtual CPU and request MPC750 CPU aka G3
ppc_cpu_init(grackle_obj, PPC_VER::MPC750, false, timebase_freq);
// set CPU PLL ratio to 3.5
ppc_state.spr[SPR::HID1] = 0xE << 28;
return 0;
}
static const PropMap bondi_settings = {
{"rambank1_size", new IntProperty(128, std::vector<uint32_t>({8, 16, 32, 64, 128, 256, 512}))},
{"rambank2_size", new IntProperty(128, std::vector<uint32_t>({8, 16, 32, 64, 128, 256, 512}))},
{"emmo", new BinProperty(0)},
{"hdd_config", new StrProperty("Ide0:0")},
{"cdr_config", new StrProperty("Ide1:0")},
{"pci_GPU", new StrProperty("AtiRagePro")},
};
static std::vector<std::string> bondi_devices = {
"Grackle", "BurgundySnd", "Heathrow", "AtaHardDisk", "AtapiCdrom"};
static const MachineDescription bondi_descriptor = {
.name = "imacg3",
.description = "iMac G3 Bondi Blue",
.devices = bondi_devices,
.settings = bondi_settings,
.init_func = &initialize_bondi};
REGISTER_MACHINE(imacg3, bondi_descriptor);
+5 -5
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -190,8 +190,8 @@ static rom_info rom_identity[] = {
{ 0x10f1, 1024, 0, 0, 0, 0, nullptr , nullptr , nullptr , nullptr , "PowerBook G3 Lombard" }, // PowerBook1,1
{ 0x11f4, 1024, 0, 0, 0, 0, nullptr , nullptr , "pmg3nw" , "Power Mac Yosemite" , "Power Mac B&W G3" }, // PowerMac1,1
{ 0x13f2, 1024, 0, 0, 0, 0, nullptr , nullptr , nullptr , nullptr , "iMac (233 MHz) (Bondi Blue)" }, // iMac,1
{ 0x13f3, 1024, 0, 0, 0, 0, nullptr , nullptr , nullptr , nullptr , "iMac (266,333 MHz) (Tray Loading)" }, // iMac,1
{ 0x13f2, 1024, 0, 0, 0, 0, nullptr , nullptr , "imacg3" , "iMac G3 Bondi" , "iMac (233 MHz) (Bondi Blue)" }, // iMac,1
{ 0x13f3, 1024, 0, 0, 0, 0, nullptr , nullptr , "imacg3" , "iMac G3 Tray Loading" , "iMac (266,333 MHz) (Tray Loading)" }, // iMac,1
{ 0, 1024, 0, 0x008100, 0x266f2e55, 0, "Kihei" , "P7" , nullptr , nullptr , "iMac G3 (Slot Loading)" }, // PowerMac2,1 // 2001-09-14 419f1
{ 0, 1024, 0, 0x008100, 0x55402f54, 0, "Kihei" , "P7" , nullptr , nullptr , "iMac G3 (Slot Loading)" }, // PowerMac2,1
@@ -474,7 +474,7 @@ void MachineFactory::list_machines()
cout << endl << "Supported machines:" << endl << endl;
for (auto& m : get_registry()) {
cout << setw(13) << m.first << "\t\t" << m.second.description << endl;
cout << setw(13) << right << m.first << "\t\t" << m.second.description << endl;
}
cout << endl;
@@ -562,7 +562,7 @@ void MachineFactory::print_settings(const PropMap& prop_map)
else
help = "";
cout << setw(13) << p.first << "\t\t" << help << endl;
cout << setw(13) << right << p.first << "\t\t" << help << endl;
cout << setw(13) << "\t\t\t" "Valid values: ";
+3 -3
View File
@@ -115,12 +115,12 @@ static const PropMap pm6500_settings = {
new BinProperty(0)},
{"hdd_config",
new StrProperty("Ide0:0")},
{"cdr_config",
new StrProperty("Ide0:0")},
{"pci_F1",
new StrProperty("AtiRageGT")},
};
static std::vector<std::string> pm6500_devices = {
"Psx", "PsxPci1", "ScreamerSnd", "OHare", "AtaHardDisk" /*, "AtapiCdrom" */
"Psx", "PsxPci1", "ScreamerSnd", "OHare", "AtaHardDisk"
};
static const MachineDescription pm6500_descriptor = {
+26 -11
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -135,10 +135,6 @@ int initialize_gossamer(std::string& id)
grackle_obj->pci_register_device(
DEV_FUN(0x10,0), dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name("Heathrow")));
std::string gpu = GET_STR_PROP("pci_GPU");
if (gpu.empty())
SET_STR_PROP("pci_GPU", id == "pmg3twr" ? "AtiRagePro" : "AtiRageGT");
// add Athens clock generator device and register it with the I2C host
gMachineObj->add_device("Athens", std::unique_ptr<AthensClocks>(new AthensClocks(0x28)));
I2CBus* i2c_bus = dynamic_cast<I2CBus*>(gMachineObj->get_comp_by_type(HWCompType::I2C_HOST));
@@ -165,19 +161,38 @@ int initialize_gossamer(std::string& id)
return 0;
}
static const PropMap gossamer_settings = {
static const PropMap gossamer_desktop_settings = {
{"rambank1_size",
new IntProperty(256, std::vector<uint32_t>({8, 16, 32, 64, 128, 256}))},
new IntProperty(256, std::vector<uint32_t>({8, 16, 32, 64, 128, 256, 512}))},
{"rambank2_size",
new IntProperty( 0, std::vector<uint32_t>({0, 8, 16, 32, 64, 128, 256}))},
new IntProperty( 0, std::vector<uint32_t>({0, 8, 16, 32, 64, 128, 256, 512}))},
{"rambank3_size",
new IntProperty( 0, std::vector<uint32_t>({0, 8, 16, 32, 64, 128, 256}))},
new IntProperty( 0, std::vector<uint32_t>({0, 8, 16, 32, 64, 128, 256, 512}))},
{"emmo",
new BinProperty(0)},
{"hdd_config",
new StrProperty("Ide0:0")},
{"cdr_config",
new StrProperty("Ide1:0")},
{"pci_GPU",
new StrProperty("AtiRageGT")},
};
static const PropMap gossamer_tower_settings = {
{"rambank1_size",
new IntProperty(256, std::vector<uint32_t>({8, 16, 32, 64, 128, 256, 512}))},
{"rambank2_size",
new IntProperty( 0, std::vector<uint32_t>({0, 8, 16, 32, 64, 128, 256, 512}))},
{"rambank3_size",
new IntProperty( 0, std::vector<uint32_t>({0, 8, 16, 32, 64, 128, 256, 512}))},
{"emmo",
new BinProperty(0)},
{"hdd_config",
new StrProperty("Ide0:0")},
{"cdr_config",
new StrProperty("Ide1:0")},
{"pci_GPU",
new StrProperty("AtiRagePro")},
};
static std::vector<std::string> pmg3_devices = {
@@ -192,7 +207,7 @@ static const MachineDescription pmg3dt_descriptor = {
.name = "pmg3dt",
.description = "Power Macintosh G3 (Beige) Desktop",
.devices = pmg3_devices,
.settings = gossamer_settings,
.settings = gossamer_desktop_settings,
.init_func = &initialize_gossamer
};
@@ -200,7 +215,7 @@ static const MachineDescription pmg3twr_descriptor = {
.name = "pmg3twr",
.description = "Power Macintosh G3 (Beige) Tower",
.devices = pmg3twr_devices,
.settings = gossamer_settings,
.settings = gossamer_tower_settings,
.init_func = &initialize_gossamer
};
+1 -4
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -194,9 +194,6 @@ typedef std::map<std::string, BasicProperty*> PropMap;
extern std::map<std::string, std::unique_ptr<BasicProperty>> gMachineSettings;
/** Conveniency macros to hide complex casts. */
#define SET_STR_PROP(name, value) \
dynamic_cast<StrProperty*>(gMachineSettings.at(name).get())->set_string(value)
#define GET_STR_PROP(name) \
dynamic_cast<StrProperty*>(gMachineSettings.at(name).get())->get_string()
+3 -4
View File
@@ -175,13 +175,12 @@ static_const_pm7500_settings(604)
static_const_pm7500_settings(604e)
static std::vector<std::string> pm7500_devices = {
"Hammerhead", "Bandit1", "Chaos", "ScsiMesh", "MeshTnt", "GrandCentral",
"ControlVideo"
"Hammerhead", "Bandit1", "ScsiMesh", "MeshTnt", "GrandCentral", "Chaos"
};
static std::vector<std::string> pm8500_devices = {
"Hammerhead", "Bandit1", "Chaos", "ScsiMesh", "MeshTnt", "GrandCentral",
"ControlVideo", "Sixty6Video"
"Hammerhead", "Bandit1", "ScsiMesh", "MeshTnt", "GrandCentral", "Chaos",
"Sixty6Video"
};
static std::vector<std::string> pm9500_devices = {
+6 -4
View File
@@ -108,19 +108,21 @@ int initialize_yosemite(std::string& id)
static const PropMap yosemite_settings = {
{"rambank1_size",
new IntProperty(256, std::vector<uint32_t>({8, 16, 32, 64, 128, 256}))},
new IntProperty(256, std::vector<uint32_t>({8, 16, 32, 64, 128, 256, 512}))},
{"rambank2_size",
new IntProperty( 0, std::vector<uint32_t>({0, 8, 16, 32, 64, 128, 256}))},
new IntProperty( 0, std::vector<uint32_t>({0, 8, 16, 32, 64, 128, 256, 512}))},
{"rambank3_size",
new IntProperty( 0, std::vector<uint32_t>({0, 8, 16, 32, 64, 128, 256}))},
new IntProperty( 0, std::vector<uint32_t>({0, 8, 16, 32, 64, 128, 256, 512}))},
{"rambank4_size",
new IntProperty( 0, std::vector<uint32_t>({0, 8, 16, 32, 64, 128, 256}))},
new IntProperty( 0, std::vector<uint32_t>({0, 8, 16, 32, 64, 128, 256, 512}))},
{"emmo",
new BinProperty(0)},
{"hdd_config",
new StrProperty("CmdAta0:0")},
{"cdr_config",
new StrProperty("Ide0:0")},
{"pci_J12",
new StrProperty("AtiMach64Gx")},
};
static std::vector<std::string> yosemite_devices = {
+4 -4
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -62,10 +62,10 @@ static void sigabrt_handler(int signum) {
}
static string appDescription = string(
"\nDingusPPC - Alpha 1.02 (3/14/2025) "
"\nDingusPPC - Alpha 1.03 (5/5/2025) "
"\nWritten by divingkatae, maximumspatium, "
"\njoevt, mihaip, kkaisershot, et. al. "
"\n(c) 2018-2024 The DingusPPC Dev Team. "
"\n(c) 2018-2025 The DingusPPC Dev Team. "
"\nThis is a build intended for testing. "
"\nUse at your own discretion. "
"\n"
@@ -228,7 +228,7 @@ int main(int argc, char** argv) {
sa.allow_extras();
std::string value;
sa.add_option("--" + name, value);
sa.add_option("--" + name, value)->expected(0,1);
try {
sa.parse(app.remaining_for_passthrough());
} catch (const CLI::Error& e) {
+16 -11
View File
@@ -229,7 +229,8 @@ namespace loguru
return false;
}
if (const char* term = getenv("TERM")) {
return 0 == strcmp(term, "cygwin")
return 0 == strcmp(term, "alacritty")
|| 0 == strcmp(term, "cygwin")
|| 0 == strcmp(term, "linux")
|| 0 == strcmp(term, "rxvt-unicode-256color")
|| 0 == strcmp(term, "screen")
@@ -436,7 +437,7 @@ namespace loguru
Text textprintf(const char* format, ...)
{
va_list vlist;
va_list vlist = {};
va_start(vlist, format);
auto result = vtextprintf(format, vlist);
va_end(vlist);
@@ -567,8 +568,8 @@ namespace loguru
else if (c == '\\') { out += "\\\\"; }
else if (c == '\'') { out += "\\\'"; }
else if (c == '\"') { out += "\\\""; }
else if (c == ' ') { out += "\\ "; }
else if (0 <= c && c < 0x20) { // ASCI control character:
else if (c == ' ') { out += "\\ "; }
else if (std::iscntrl(c)) { // ASCI control character:
// else if (c < 0x20 || c != (c & 127)) { // ASCII control character or UTF-8:
out += "\\x";
write_hex_byte(out, static_cast<uint8_t>(c));
@@ -801,6 +802,10 @@ namespace loguru
const char* mode_str = (mode == FileMode::Truncate ? "w" : "a");
FILE* file;
#ifdef _WIN32
#ifndef _SH_DENYNO
#define _SH_DENYNO 0x40
#endif // !_SH_DENYNO
file = _fsopen(path, mode_str, _SH_DENYNO);
#else
file = fopen(path, mode_str);
@@ -1101,7 +1106,7 @@ namespace loguru
long thread_id;
(void)thr_self(&thread_id);
#elif LOGURU_PTHREADS
uint64_t thread_id = pthread_self();
uint64_t thread_id = (uint64_t)pthread_self();
#else
// This ID does not correllate to anything we can get from the OS,
// so this is the worst way to get the ID.
@@ -1510,7 +1515,7 @@ namespace loguru
#else
void log(Verbosity verbosity, const char* file, unsigned line, const char* format, ...)
{
va_list vlist;
va_list vlist = {};
va_start(vlist, format);
vlog(verbosity, file, line, format, vlist);
va_end(vlist);
@@ -1524,7 +1529,7 @@ namespace loguru
void raw_log(Verbosity verbosity, const char* file, unsigned line, const char* format, ...)
{
va_list vlist;
va_list vlist = {};
va_start(vlist, format);
auto buff = vtextprintf(format, vlist);
auto message = Message{verbosity, file, line, "", "", "", buff.c_str()};
@@ -1555,7 +1560,7 @@ namespace loguru
LogScopeRAII::LogScopeRAII(Verbosity verbosity, const char* file, unsigned line, const char* format, ...) :
_verbosity(verbosity), _file(file), _line(line)
{
va_list vlist;
va_list vlist = {};
va_start(vlist, format);
this->Init(format, vlist);
va_end(vlist);
@@ -1624,7 +1629,7 @@ namespace loguru
#else
void log_and_abort(int stack_trace_skip, const char* expr, const char* file, unsigned line, const char* format, ...)
{
va_list vlist;
va_list vlist = {};
va_start(vlist, format);
auto buff = vtextprintf(format, vlist);
log_to_everywhere(stack_trace_skip + 1, Verbosity_FATAL, file, line, expr, buff.c_str());
@@ -1665,7 +1670,7 @@ namespace loguru
std::string strprintf(const char* format, ...)
{
va_list vlist;
va_list vlist = {};
va_start(vlist, format);
auto result = vstrprintf(format, vlist);
va_end(vlist);
@@ -1842,7 +1847,7 @@ namespace loguru
else if (c == '\n') { str += "\\n"; }
else if (c == '\r') { str += "\\r"; }
else if (c == '\t') { str += "\\t"; }
else if (0 <= c && c < 0x20) {
else if (std::iscntrl(c)) {
str += "\\u";
write_hex_16(static_cast<uint16_t>(c));
} else { str += c; }
+2 -2
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -91,7 +91,7 @@ void Profiler::print_profile(std::string name)
}
}
std::cout << std::endl;
std::cout << std::right << std::endl;
}
void Profiler::reset_profile(std::string name)
+9 -3
View File
@@ -1,4 +1,4 @@
The AMIC is the I/O controller used in the Power Mac 6100.
The AMIC is the I/O controller used in the Power Mac 6100. Physically, it's located at 0x50F00000.
It also:
@@ -8,7 +8,13 @@ It also:
| Subdevice | Range |
|:--------------:|:--------------------:|
| VIA Cuda | 0x0 - 0x1FFF |
| VIA 1 | 0x0 - 0x1FFF |
| SCC | 0x4000 - 0x5FFF |
| MACE | 0xA000 - 0xBFFF |
| SCSI | 0x10000 - 0x11FFF |
| DMA | 0x31000 - 0x32FFF |
| AWACS | 0x14000 - 0x15FFF |
| SWIM III | 0x16000 - 0x17FFF |
| VIA 2 | 0x26000 - 0x27FFF |
| Video | 0x28000 - 0x29FFF |
| DMA | 0x31000 - 0x32FFF |
| Mem Control | 0x40000 - 0x41FFF |
+1 -1
View File
@@ -28,7 +28,7 @@ All registers are 32-bit here.
| Byte Swapping | 0x40 |
| Frame Count | 0x50 |
##Sound Control Register bits
## Sound Control Register bits
| Register | Bit Mask |
|:-------------------------:|:--------:|
+4
View File
@@ -111,6 +111,10 @@ PowerPC supports both big-endian and little-endian modes. Mac OS largely operate
* To accommodate for early programs compiled on PowerPC 601 Macs, the classic Mac OS has to emulate the POWER instructions that were removed from later processors.
* BeOS uses the exception handler by deliberately invoking a supervisor-level instruction while the PR bit is set in the MSR.
* Mac OS X touches the FP bit in the MSR to performing floating-point operations.
# References
http://www.ibmfiles.com/ibmfiles/powerpc/itso_powerpc_inside_view.pdf
+20 -1
View File
@@ -2,7 +2,7 @@
The Old World ROM is always 4 megabytes (MB). The first three MB are reserved for the 68k code, while the last MB is for the PowerPC boot-up code.
New World ROMs are 1 MB stubs containing OpenFirmware and some basic drivers, but has an additional ROM stored on the Mac's hard disk to provide Toolbox functionality. The ROMs stored on the Mac's hard disk also had updates distributed.
New World ROMs are 1 MB stubs containing Open Firmware and some basic drivers, but has an additional ROM stored on the Mac's hard disk to provide Toolbox functionality. The ROMs stored on the Mac's hard disk also had updates distributed.
Within Apple, the project to overhaul Mac OS ROM code from separate portable, low-end, and high-end branches into a single codebase was called SuperMario.
@@ -63,6 +63,25 @@ On a physical machine, one has to hold the Command/Apple, Option, P and R keys t
This video RAMDAC appears to be exclusive to the Power Mac 7200.
# Ariel
Video controller used by the Power Mac 6100. It can support up to 16-bit color.
| Register Name | Address |
|:----------------:|:--------:|
| Address | 0x24000 |
| Color Data | 0x24001 |
| Control | 0x24002 |
| Key Color | 0x24003 |
| Video Mode | 0x28000 |
| Color | 0x28001 |
| Monitor ID | 0x28002 |
| Video Test | 0x28003 |
| Horiz. Test High | 0x28004 |
| Horiz. Test Low | 0x28005 |
| Vert. Test High | 0x28006 |
| Vert. Test Low | 0x28007 |
# USB
Support is only present in New World Macs, despite the presence of strings in the Power Mac G3 Beige ROM. Most Macs support 1.1, with 2.0 support present in G5 Macs. Both it and Firewire follow the Open Host Controller Interface (OHCI) standard.
+4
View File
@@ -1,5 +1,9 @@
The following document is intended primarily as a documentation on how the Motorola Atlas operates. It is currently not implemented in DingusPPC.
## General
The computer generally follows the PReP standard, but there is some x86 emulation for using the VGA BIOS.
## Sources
* https://cdn.preterhuman.net/texts/computing/chrp_prep/ambih.pdf
+33 -15
View File
@@ -3,19 +3,31 @@
## Implemented Features
* Interpreter (with 601, FPU, and MMU support)
* IDE and SCSI
* IDE and SCSI
* Floppy disk image reading (Raw, Disk Copy 4.2, WOZ v1 and v2)
* ADB mouse, keyboard, and AppleJack (Pippin) controller emulation
* ADB mouse, keyboard, and AppleJack (Pippin) controller
* Some audio support
* Basic video output support (i.e. ATI Rage, Control, Platinum)
## Known Working OSes
* Disk Tools (7.1.2 - 8.5)
* Mac OS 7.1.2 - 9.2.2 (from CD)
* Mac OS 7.5.3 - 9.2.2 (from Hard Disk)
* Disk Tools (7.1.2 - 8.5)
* Mac OS 7.1.2 - 9.2.2 (from CD or Hard Disk)
* Mac OS X 10.0 - 10.3
* OpenDarwin 6.6.2
## Disk Initialization
To initialize a disk, you'll first need to boot Disk Tools from a floppy disk image along with a blank hard disk image you want to initialize.
Once booted, start up the Hard Disk Setup application and initialize the drive listed. It may be listed as not mounted.
Once the disk has been initialized, you will need to reboot the machine with the appropriate installation media, such as a CD-ROM image.
Make sure the disk is appropriately sized for the OS you want to install and follow the instructions from the installer carefully.
You may also want to use a third-party program like BlueSCSI to convert a raw HFS image from an emulator like SheepShaver.
## Windows
DingusPPC uses two windows when booted up; a command line window and a monitor window to display the machine.
@@ -69,7 +81,7 @@ Shows the configurable properties, such as the selected disc image and the ram b
--rambank4_size X
```
Set the RAM sizes to use, with X being an integer of a power of 2 up to 256.
Set the RAM sizes to use, with X being an integer of a power of 2 up to 512 (depending on the emulated machine).
```
--fdd_img TEXT:FILE
@@ -112,13 +124,13 @@ Access the factory tests
--serial_backend=socket
```
Set the ADB devices to attach, comma-separated
Change where the output of Open Firmware is directed to, either to the command line (with stdio) or a Unix socket (unavailable in Windows builds). Open Firmware 1.x outputs here by default.
```
--adb_devices TEXT
```
Change where the output of OpenFirmware is directed to, either to the command line (with stdio) or a Unix socket (unavailable in Windows builds). OpenFirmware 1.x outputs here by default.
Set the ADB devices to attach, comma-separated.
### Command Line Examples
@@ -126,7 +138,7 @@ Change where the output of OpenFirmware is directed to, either to the command li
dingusppc -b bootrom-6100.bin --rambank1_size 64 --rambank2_size 64 --hdd_img "System_712.dsk"
```
The user has specified their own ROM file, which is for a Power Macintosh 6100 and has also set up two separate RAM banks to use 64 MB. Note that if a second RAM bank is to be specified for the 6100, it should be the same size as the first RAM bank. With only a hard disk specified, the machine will immediately boot to the OS on the hard disk.
The user has specified their own ROM file, which is for a Power Macintosh 6100 and has also set up two separate RAM banks to use 64 MB each. Note that if a second RAM bank is to be specified for the 6100, it should be the same size as the first RAM bank. With only a hard disk specified, the machine will immediately boot to the OS on the hard disk.
```
dingusppc -b "Power_Mac_G3_Beige.ROM" -r --rambank1_size 128 --fdd_img "DiskTools_8.5.img"
@@ -140,24 +152,26 @@ dingusppc -b "Power_Mac_G3_Beige.ROM" -d --rambank1_size 64 --rambank2_size 64 -
The debugger will be turned on here, due to the presence of `-d`. The CD ROM image will be loaded in.
## Accessing OpenFirmware
## Accessing Open Firmware
After booting from a PCI Power Mac ROM without any disk images, enter the debugger and change the NVRAM property `auto-boot?` to false. Quit of the emulator and boot it back up to access it.
After booting from a PCI Power Mac ROM without any disk images, enter the debugger and change the NVRAM property `auto-boot?` to false. Exit out of the emulator and boot it back up to access it.
## Supported machines
The machines that currently work the best are the Power Mac 6100, the Power Mac 7500, and the Power Mac G3.
Early implementations for the Power Mac G3 Blue and White and the Apple Pippin are also present.
Early implementations of the iMac G3, Power Mac G3 Blue and White, and Apple Pippin are also present.
## Debugger
The debugger can be used to not only see what code is being executed at a given moment, but also see what is stored in an NVRAM portion.
The debugger can be used to show what code is currently being executed, the contents of memory as hex or 68K assembly or PowerPC assembly, NVRAM variables, memory regions, and CPU registers. It can also be used to change memory, registers, and nvram variables. It can step through instructions one at a time or many instructions at once.
## Quirks
### Mouse Grabbing
While the emulator window is in focus, press Control and G to access.
While the emulator display window is in focus, press Control-G to hide the host mouse cursor to control the guest mouse cursor directly. Press Control-G to show the host mouse cursor again and control the guest mouse cursor only when the host mouse cursor is within the emulator display window.
Press Control-S to toggle the scaling method of the emulator display window. The methods are nearest (best used when the scale factor is an integer value) and linear (or smooth mode which is not as sharp but helps display quality when the scale factor is not an integer value).
### CD ROM Images
@@ -169,7 +183,11 @@ Because Sheepshaver, Basilisk II, and Mini vMac operate on raw disks, it is requ
### OS Support
Currently, the Power Mac 6100 cannot boot any OS image containing Mac OS 8.0 or newer.
Currently, the Power Mac 6100 cannot boot any OS image containing Mac OS 9.0 or newer.
### ATI Mach Support
The GUI engine is currently not fully implemented. As such, UI elements might not be rendered when trying to use this video card. To circumenvent this, you may wish to move the ATI Accelerator extension to the Extensions (Disabled) folder.
### Currently Unimplemented Features