Compare commits

...
94 Commits
Author SHA1 Message Date
joevt dfea8fa2cd debugger: Show register values during stepping.
So you don't need to use regs after every instruction.
2026-03-31 07:55:21 -07:00
joevt 07f781bf56 debugger: Disassemble instructions while stepping. 2026-03-31 07:54:57 -07:00
joevt 91f5ccc3f9 ppcmmu: Simplify pteg address calculation.
Maybe the optimizer can do it or maybe not.
2026-03-31 07:39:45 -07:00
Maxim Poliakovski 995da89bda scsiblockcmds: fix block descriptor.
SCSI-3 standard specifies a slightly different format for
the short block descriptor applied to direct-access devices.
2026-03-24 20:15:53 +01:00
dingusdev d1d496fda9 Version Prep 2026-03-23 19:30:44 -07:00
joevt bf7fc5fb5a viacuda: Postpone onesec timer if SR int pending. 2026-03-23 07:26:19 -07:00
joevt e275635697 main: Cancel all timers before restart.
Some devices do not cancel their timers when destructed.
If they exist after restart, then bad things can happen.
2026-03-22 17:15:53 -07:00
joevt d8d7ebd40c timermanager: Check for empty queue before remove. 2026-03-22 17:15:35 -07:00
joevt fa6abacf4e hostevents: mouse relative coordinates are signed. 2026-03-22 17:14:06 -07:00
joevt ef8c83108c CLI11: Update to v2.6.2. 2026-03-20 07:00:38 -07:00
joevt 0b32714200 README: Cleanup and add some cmake notes. 2026-03-19 19:33:00 -07:00
joevt c6f17a846b escc: Make W7Prime a peer of WR7.
This simplifies the switch statement and storage of register values.
2026-03-14 15:56:50 -07:00
joevt fb02b15063 escc: Update brg_clock_src when it changes. 2026-03-14 15:55:35 -07:00
joevt ff3e66ecd7 adbmouse: Use parameter for buttons state.
- Rename the parameter from buttons_state to buttons so it is not
  confused with the class data member.

- AdbAppleJack triggers should affect mouse button state in register 0.
  That means AdbMouse::get_register_0 needs to use the buttons parameter
  instead of the buttons_state class data member.
2026-03-12 20:50:35 -07:00
joevt 626497bdc0 adbapplejack: Rename buttons_state.
So that it is not confused with buttons_state of AdbMouse.
2026-03-12 20:50:28 -07:00
Maxim Poliakovski 0b018bd0a4 scsihd: use generic START_STOP_UNIT. 2026-03-12 01:59:23 +01:00
Maxim Poliakovski 9505745006 scsiblockcmds: generic START_STOP_UNIT. 2026-03-12 01:59:23 +01:00
Maxim Poliakovski b62bb5ffa4 blockstoragedevice.h: fix indentation. 2026-03-10 16:32:45 +01:00
Maxim Poliakovski 46901d8d03 scsihd: use generic PREVENT_ALLOW_MEDIUM_REMOVAL. 2026-03-10 16:32:45 +01:00
Maxim Poliakovski cb1e318a28 scsiblockcmds: generic PREVENT_ALLOW_MEDIUM_REMOVAL. 2026-03-10 16:32:45 +01:00
Maxim Poliakovski 93bca96794 scsiphysinterface.h: add set_eject_state method. 2026-03-10 16:32:45 +01:00
joevt 917eec6ff4 CMakeLists.txt: Fix testppc copy command.
The destination of the .csv files should be that of the testppc
executable, not the dingusppc executable.

On Apple platform, the dingusppc executable may be a bundle and copying
the .csv files into the bundle causes a code signing error.
2026-03-10 07:10:11 -07:00
Maxim Poliakovski 954a277bb3 scsihd: remove stub for REASSIGN. 2026-03-10 01:12:51 +01:00
Maxim Poliakovski 202446025a scsiphysdevice: implement writing of big data in chunks. 2026-03-10 00:41:45 +01:00
Maxim Poliakovski f2a9f3cb56 scsi.h: add write_more_data callback. 2026-03-10 00:41:31 +01:00
Tim Jarzombek ad4515721b amic: Emulate SCC receive DMA registers instead of returning random values.
The SCC DMA Receive control registers previously returned std::rand(),
a workaround to unblock Mac OS 8.5/8.5.1 boot which polls these
registers expecting specific bit patterns. This caused non-deterministic
bimodal boot times (~10s vs ~18s) on Power Mac 6100 as the guest would
sometimes enter a ~7s polling loop depending on the random value.

Add AmicSerialRcvDma to properly track the control register and byte
count state for both SCC receive channels. Writes now update the status
byte using the same bit manipulation as the transmit DMA channels, and
reads return the tracked state. Also wire up the RX byte count registers
(SCC_RXA/B_Byte_Cnt_Hi/Lo) which were previously ignored on write.
2026-03-08 18:34:00 -07:00
dingusdevandTim Jarzombek 3decd4b9fc Cuda improvements
* Implements missing Cuda commands
* Proper One Second Mode handling
* Add Stat Response ADB bit
* Typo fixes

Co-Authored-By: Tim Jarzombek <[email protected]>
2026-03-08 16:26:47 -07:00
joevt 16117e6c60 escc: Add channel and direction enums.
Also fix dma_ch index in dma_out_tx, dma_flush_tx.
2026-03-08 10:54:09 -07:00
joevt 9bae84ff07 z85c30: Cleanup and missing info. 2026-03-08 10:51:09 -07:00
joevt 4ca03953d7 ppcemu: Fix EAR spr exception. 2026-03-08 10:42:22 -07:00
joevt dd31610013 viacuda: Increase input buffer size to 259 bytes. 2026-03-08 10:13:08 -07:00
dingusdev 8b2c0b0de9 Slightly safer way to use read_more_data 2026-02-24 18:51:54 -07:00
Maxim Poliakovski 6075807998 scsihd: use new MODE SENSE implementation. 2026-02-23 18:34:31 +01:00
Maxim Poliakovski 9d5373120d scsiblockcmds: fix parameters for error recovery page. 2026-02-23 16:12:28 +01:00
Maxim Poliakovski 6c29738441 scsihd: pass reads and writes to ScsiBlockCmds. 2026-02-23 03:58:45 +01:00
Maxim Poliakovski a8ff30ef36 New class ScsiBlockCmds. 2026-02-23 03:50:16 +01:00
Maxim Poliakovski 20dfe798ac scsicommoncmds: implement generic MODE SENSE. 2026-02-23 03:12:59 +01:00
Maxim Poliakovski 1a8d691777 scsi.h: more mode sense page codes. 2026-02-23 01:48:09 +01:00
Maxim Poliakovski 34b4d6387d blockstoragedevice: clean up and add write support. 2026-02-23 01:09:23 +01:00
Maxim Poliakovski 9ca3e5e870 scsiphysinterface.h: more callbacks. 2026-02-23 00:40:56 +01:00
Maxim Poliakovski 0d25f6dc33 scsi.h: rename READ_CAPACITY_10 to READ_CAPACITY. 2026-02-22 23:48:28 +01:00
Maxim Poliakovski 2735449c75 scsiphysdevice: fix send_data() again to support big transfers. 2026-02-22 22:23:03 +01:00
Maxim Poliakovski 6092882a45 ppcopcodes: fix bit test in eciwx/ecowx. 2026-02-22 18:17:29 +01:00
Maxim Poliakovski 345bcf8a73 scsiphysdevice: remove prepare_data method.
Clean up and simplify buffer setup for various
data transfer phases.
2026-02-19 02:42:59 +01:00
Maxim Poliakovski 6e18241be6 scsiphysinterface: add set_buffer method. 2026-02-19 02:33:29 +01:00
Maxim Poliakovski a9fcde836c Replace get_more_data method with a callback. 2026-02-17 16:06:00 +01:00
Maxim Poliakovski b52a7bebbc scsiphysdevice.cpp: improve send_data() method. 2026-02-17 16:06:00 +01:00
Maxim Poliakovski 6033f75521 scsicommoncmds: minor fixes. 2026-02-15 21:15:50 +01:00
Maxim Poliakovski 2ea8fee204 blockstoragedevice: switch parameter for set_fpos to uint64_t. 2026-02-15 21:15:50 +01:00
Maxim Poliakovski 25a5f193ba blockstoragedevice: assign default value to the 2nd param of read_begin. 2026-02-15 21:15:50 +01:00
dingusdev d9bcb47beb Set up code for Mac OS X bundles 2026-02-15 21:15:50 +01:00
Tim Jarzombek 398e0b025d Fix bugs caught by fuzzing 2026-02-12 21:11:11 -05:00
Maxim Poliakovski cbff26539a scsi.h: add constants for page control in MODE SENSE. 2026-02-12 01:23:00 +01:00
Maxim Poliakovski 8a280f71ab Move page numbers for MODE SENSE to scsi.h 2026-02-12 01:06:34 +01:00
Tim Jarzombek 3545296e3a ci: add macOS (arm64 and x64), general refactor (#163)
- Adds macOS builds on arm64 and x64
- Caching to improve build speeds
- Upload build logs on failure
- Retain PR artifacts for 7 days, others for 30 days
2026-02-09 07:22:50 -07:00
joevt b182e01218 viacuda: Avoid float in VIA timer calculations.
- float is limited to 24 bits so use longer uint32_t or uint64_t.
- Rename the formal parameter so it more closely matches the actual
  parameter. Also, don't hide the class field.
- Multiply is faster than divide.
2026-02-07 20:51:48 -07:00
Maxim Poliakovski 200a2aa9a7 Move SCSI devices to new architecture.
That implies a clear separation between implementation
of the SCSI commands and the physical device layer.
2026-02-08 02:38:02 +01:00
Maxim Poliakovski 470c9a32f5 Implement common SCSI commands in a separate class. 2026-02-08 02:22:23 +01:00
Maxim Poliakovski 44343ad591 New interface for physical SCSI/ATAPI layer abstraction. 2026-02-08 02:22:23 +01:00
Maxim Poliakovski 022d5e4e00 scsi.h: add enum for device capabilities. 2026-02-07 03:00:09 +01:00
Maxim Poliakovski 3dde616c57 scsihd.h: add missing overrides. 2026-02-06 21:57:51 +01:00
Maxim Poliakovski b82dae7ad6 scsihd: remove unused send_diagnostic() stub. 2026-02-04 19:15:37 +01:00
Maxim Poliakovski 924cc5ed97 scsi.h: remove definitions for vendor specific commands. 2026-02-04 18:52:01 +01:00
Maxim Poliakovski 0570513ff1 scsicdrom: remove vendor specific commands. 2026-02-04 18:52:01 +01:00
Maxim Poliakovski fd8d89b711 scsi.h: set subtype for ScsiSense and ScsiError to uint8_t. 2026-02-04 17:58:55 +01:00
Maxim Poliakovski 17f13e8eb3 scsiphysdevice: cleanup logging. 2026-02-04 16:35:32 +01:00
Maxim Poliakovski 8e9ee07e9b Rename ScsiDevice to ScsiPhysDevice. 2026-02-04 15:47:05 +01:00
dingusdevandjoevt 129c5053f6 Improve ADB keyboard emulation
Co-Authored-By: joevt <[email protected]>
2026-02-04 07:21:44 -07:00
dingusdev d29e15332c Merge pull request #162 from Cacodemon345/patch-2
atirage: Implement reads/writes from/to the auxiliary aperture
2026-02-04 07:00:47 -07:00
Cacodemon345 7abc8afc97 atirage: Remove more redundant code 2026-02-04 17:23:41 +06:00
Cacodemon345 4c3989fa13 atirage: Remove unreachable logging for auxiliary aperture 2026-02-04 17:19:08 +06:00
Cacodemon345 6a3654e851 atirage: Implement reads/writes from the auxiliary aperture 2026-02-04 16:56:19 +06:00
Cacodemon345 7c29e41fae atirage: Definitions for auxiliary register aperture 2026-02-04 16:47:57 +06:00
Maxim Poliakovski 7e07919d7c scsi.h: add device types enum. 2026-02-01 02:10:08 +01:00
Maxim Poliakovski 7d4ebf5bf1 Fix spelling. 2026-02-01 02:10:08 +01:00
dingusdevandAndrew Randrianasulu 79c9b5f63e Update manual.md
Co-Authored-By: Andrew Randrianasulu <[email protected]>
2026-01-31 08:36:35 -07:00
Maxim Poliakovski 0fee0a5270 control: reduce logging noise.
Mac OS 7.5.5 accesses the monitor sense register many times.
This causes a huge amount of pointless log messages.
This commit changes priority of the log messages
for the monitor sense registers so none will be displayed
by default.
2026-01-31 15:11:12 +01:00
joevt 60d4750d54 ppcopcodes: Decrementer fixes.
- Always add a tick to the timeout calculation.
- Make sure value of decrementer is < 0 for timed decrementer exception.
- Don't recalculate decrementer write time stamp in the case of an
  immediate decrementer exception.
2026-01-31 13:17:22 +01:00
dingusdev 213dd4c16e Update copyright info further 2026-01-30 08:12:04 -07:00
Maxim Poliakovski 0d22d5cbd8 ppcopcodes: fix decrementer interrupts.
Enable decrementer interrupts for MPC601
required by  MkLinux DR3.
2026-01-30 15:40:15 +01:00
joevt 140c9adb0c hostevents_sdl: Fix INTERNATIONAL3 for non-Japan. 2026-01-30 15:40:15 +01:00
joevt 489bd0dfcf viacuda: Fix append_data. 2026-01-30 07:06:03 -07:00
Maxim Poliakovski e75ee8d32a Update copyright year. 2026-01-30 12:15:00 +01:00
joevt 769ef49f67 ppcopcodes: Implement mfspr for tbl_u and tbu_u. 2026-01-29 07:53:37 -07:00
joevt e0677a8a1f ppcexec: Add TBL_U and TBU_U for reg_op. 2026-01-29 07:53:27 -07:00
joevt 356e74f8c2 ppcdisasm: Cleanup spr calculation. 2026-01-29 07:53:17 -07:00
joevt 3e8121c1f5 ppcdisasm: Add tbl_u and tbu_u for mfspr. 2026-01-29 07:53:02 -07:00
Maxim Poliakovski c2df2e4ad2 sc53c94: fix int_status for CMD_COMPLETE_STEPS.
No known manual specifies interrupt status for COMPLETE_STEPS.
MkLinux DR3 expects that int_status contains INTSTAT_SO after
this command.
2026-01-25 03:32:28 +01:00
Maxim Poliakovski df36ad8369 scsihd: temporarily fix req_sense(). 2026-01-25 03:01:10 +01:00
Maxim Poliakovski ad2abf4433 scsi.h: initialize REQ_SENSE state in ScsiDevice. 2026-01-25 03:01:10 +01:00
dingusdev 0ca4e14195 Clarify command line arguments 2026-01-24 15:59:53 -07:00
Maxim Poliakovski 5883b39c2b viacuda: disable async packets during Sync transaction. 2026-01-23 02:12:44 +01:00
Maxim Poliakovski 1b7338960f viacuda: fix typo. 2026-01-22 15:21:13 +01:00
joevt d693b0f443 maciotwo: Fix IDE read/write mask again.
Use the entire 4K range.
2026-01-20 07:07:11 -07:00
206 changed files with 5285 additions and 2985 deletions

No files matched your search

+236 -216
View File
@@ -4,262 +4,282 @@ on:
branches: [ master ]
pull_request:
branches: [ master ]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
jobs:
build:
build-linux:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v3
- name: install_dependencies
- uses: actions/checkout@v5
with:
submodules: recursive
- name: Cache ccache
uses: actions/cache@v5
with:
path: ${{ github.workspace }}/.ccache/linux
key: linux-ccache-${{ runner.os }}-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: linux-ccache-${{ runner.os }}-${{ env.BUILD_TYPE }}-
- name: Install dependencies
run: |
sudo apt-get update -y -qq
sudo apt-get install libsdl2-dev
- name: init_submodules
run: git submodule update --init --recursive
sudo apt-get install -y -qq libsdl2-dev ninja-build ccache
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DDPPC_68K_DEBUGGER=ON
env:
CCACHE_DIR: ${{ github.workspace }}/.ccache/linux
CCACHE_BASEDIR: ${{ github.workspace }}
run: cmake -S . -B ${{github.workspace}}/build -GNinja -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DDPPC_68K_DEBUGGER=ON -DDPPC_BUILD_PPC_TESTS=ON -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: DingusPPC-LINUX
path: ${{github.workspace}}/build/bin
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --parallel
- name: ccache stats
run: ccache --show-stats || true
- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{env.BUILD_TYPE}}
build-windows:
runs-on: windows-latest
run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure
- name: Upload logs on failure
if: failure()
uses: actions/upload-artifact@v6
with:
name: logs-${{ github.job }}
path: |
${{ github.workspace }}/build/Testing/Temporary/LastTest.log
${{ github.workspace }}/build/CMakeFiles/CMakeOutput.log
${{ github.workspace }}/build/CMakeFiles/CMakeError.log
if-no-files-found: ignore
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
- name: Upload artifact
if: always()
uses: actions/upload-artifact@v6
with:
name: DingusPPC-LINUX
path: ${{github.workspace}}/build/bin
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
build-macos:
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
cache-name: [msys64-cache]
include:
- runner: macos-latest
arch: arm64
brew_prefix: /opt/homebrew
- runner: macos-15-intel
arch: x86_64
brew_prefix: /usr/local
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v5
with:
submodules: recursive
- name: Cache ccache
uses: actions/cache@v5
with:
path: ${{ github.workspace }}/.ccache/${{ matrix.arch }}
key: macos-${{ matrix.runner }}-${{ matrix.arch }}-ccache-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: macos-${{ matrix.runner }}-${{ matrix.arch }}-ccache-${{ env.BUILD_TYPE }}-
- name: Install dependencies
run: |
export HOMEBREW_NO_AUTO_UPDATE=1
export HOMEBREW_NO_INSTALL_CLEANUP=1
brew install sdl2 ccache ninja
- name: Configure CMake
env:
CCACHE_DIR: ${{ github.workspace }}/.ccache/${{ matrix.arch }}
CCACHE_BASEDIR: ${{ github.workspace }}
run: |
export PATH="${{ matrix.brew_prefix }}/opt/ccache/libexec:$PATH"
cmake -S . -B ${{github.workspace}}/build -GNinja -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DDPPC_68K_DEBUGGER=ON -DDPPC_BUILD_PPC_TESTS=ON -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_OSX_ARCHITECTURES=${{ matrix.arch }}
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --parallel
- name: ccache stats
run: ccache --show-stats || true
- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure
- name: Upload logs on failure
if: failure()
uses: actions/upload-artifact@v6
with:
name: logs-${{ github.job }}-${{ matrix.arch }}
path: |
${{ github.workspace }}/build/Testing/Temporary/LastTest.log
${{ github.workspace }}/build/CMakeFiles/CMakeOutput.log
${{ github.workspace }}/build/CMakeFiles/CMakeError.log
if-no-files-found: ignore
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
- name: Upload artifact
if: always()
uses: actions/upload-artifact@v6
with:
name: DingusPPC-macOS-${{ matrix.arch }}
path: ${{github.workspace}}/build/bin
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
build-windows-msys2:
runs-on: windows-latest
timeout-minutes: 45
env:
MSYSTEM: MINGW64
FF_SCRIPT_SECTIONS: '0'
CONFIGURE_ARGS: '--target-list=x86_64-softmmu --without-default-devices -Ddebug=false -Doptimization=0'
TEST_ARGS: '--no-suite qtest'
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up MSYS2
run: |
Write-Output "Acquiring msys2.exe installer at $(Get-Date -Format u)"
If ( !(Test-Path -Path msys64\var\cache ) ) {
mkdir msys64\var\cache
}
Invoke-WebRequest "https://repo.msys2.org/distrib/msys2-x86_64-latest.sfx.exe.sig" -outfile "msys2.exe.sig"
if ( Test-Path -Path msys64\var\cache\msys2.exe.sig ) {
Write-Output "Cached installer sig" ;
if ( ((Get-FileHash msys2.exe.sig).Hash -ne (Get-FileHash msys64\var\cache\msys2.exe.sig).Hash) ) {
Write-Output "Mis-matched installer sig, new installer download required" ;
Remove-Item -Path msys64\var\cache\msys2.exe.sig ;
if ( Test-Path -Path msys64\var\cache\msys2.exe ) {
Remove-Item -Path msys64\var\cache\msys2.exe
}
} else {
Write-Output "Matched installer sig, cached installer still valid"
}
} else {
Write-Output "No cached installer sig, new installer download required" ;
if ( Test-Path -Path msys64\var\cache\msys2.exe ) {
Remove-Item -Path msys64\var\cache\msys2.exe
}
}
if ( !(Test-Path -Path msys64\var\cache\msys2.exe ) ) {
Write-Output "Fetching latest installer" ;
Invoke-WebRequest "https://repo.msys2.org/distrib/msys2-x86_64-latest.sfx.exe" -outfile "msys64\var\cache\msys2.exe" ;
Copy-Item -Path msys2.exe.sig -Destination msys64\var\cache\msys2.exe.sig
} else {
Write-Output "Using cached installer"
}
Write-Output "Invoking msys2.exe installer at $(Get-Date -Format u)"
msys64\var\cache\msys2.exe -y
((Get-Content -path .\msys64\etc\post-install\07-pacman-key.post -Raw) -replace '--refresh-keys', '--version') | Set-Content -Path .\msys64\etc\post-install\07-pacman-key.post
.\msys64\usr\bin\bash -lc "sed -i 's/^CheckSpace/#CheckSpace/g' /etc/pacman.conf"
.\msys64\usr\bin\bash -lc 'pacman --noconfirm -Syuu' # Core update
.\msys64\usr\bin\bash -lc 'pacman --noconfirm -Syuu' # Normal update
taskkill /F /FI "MODULES eq msys-2.0.dll"
- name: Install dependencies
run: |
Write-Output "Installing mingw packages at $(Get-Date -Format u)"
.\msys64\usr\bin\bash -lc 'pacman -Sy --noconfirm --needed \
bison \
diffutils \
flex \
tar \
doxygen \
cmake \
wget \
git \
grep \
make \
rsync \
ninja \
glib2-devel \
patch \
sed \
mingw-w64-x86_64-cmake \
mingw-w64-x86_64-binutils \
mingw-w64-x86_64-doxygen \
mingw-w64-x86_64-capstone \
mingw-w64-x86_64-ccache \
mingw-w64-x86_64-curl \
mingw-w64-x86_64-cyrus-sasl \
mingw-w64-x86_64-dtc \
mingw-w64-x86_64-gcc \
mingw-w64-x86_64-glib2 \
mingw-w64-x86_64-gnutls \
mingw-w64-x86_64-gtk3 \
mingw-w64-x86_64-libgcrypt \
mingw-w64-x86_64-libjpeg-turbo \
mingw-w64-x86_64-libnfs \
mingw-w64-x86_64-libpng \
mingw-w64-x86_64-libssh \
mingw-w64-x86_64-libtasn1 \
mingw-w64-x86_64-libusb \
mingw-w64-x86_64-lzo2 \
mingw-w64-x86_64-libslirp \
mingw-w64-x86_64-nettle \
mingw-w64-x86_64-clang \
mingw-w64-x86_64-ninja \
mingw-w64-x86_64-pixman \
mingw-w64-x86_64-pkgconf \
mingw-w64-x86_64-python \
mingw-w64-x86_64-SDL2 \
mingw-w64-x86_64-SDL2_image \
mingw-w64-x86_64-snappy \
mingw-w64-x86_64-spice \
mingw-w64-x86_64-usbredir \
mingw-w64-x86_64-zstd \
mingw-w64-x86_64-make'
- name: init_submodules
run: git submodule update --init --recursive
uses: actions/checkout@v5
with:
submodules: recursive
- name: Cache ccache
uses: actions/cache@v5
with:
path: ${{ github.workspace }}/.ccache/msys
key: windows-msys-ccache-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: windows-msys-ccache-${{ env.BUILD_TYPE }}-
- name: Setup MSYS2
uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
update: true
install: >-
cmake
ninja
git
mingw-w64-x86_64-cmake
mingw-w64-x86_64-gcc
mingw-w64-x86_64-binutils
mingw-w64-x86_64-ninja
mingw-w64-x86_64-pkgconf
mingw-w64-x86_64-SDL2
mingw-w64-x86_64-ccache
- name: Build
shell: msys2 {0}
run: |
echo "Running build at $(date -u +'%Y-%m-%dT%H:%M:%SZ')"
export CHERE_INVOKING=yes
export MSYS=winsymlinks:native
export CCACHE_BASEDIR="${GITHUB_WORKSPACE}"
export CCACHE_DIR="${GITHUB_WORKSPACE}/.ccache/msys"
export CCACHE_DEPEND=1
ccache --zero-stats || true
cmake -S . -B build -GNinja -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DDPPC_68K_DEBUGGER=ON -DDPPC_BUILD_PPC_TESTS=ON -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
cmake --build build --config ${{ env.BUILD_TYPE }} --parallel
ccache --show-stats || true
echo "Finished build at $(date -u +'%Y-%m-%dT%H:%M:%SZ')"
- name: Test
shell: msys2 {0}
run: |
Write-Output "Running build at $(Get-Date -Format u)"
$env:CHERE_INVOKING = 'yes' # Preserve the current working directory
$env:MSYS = 'winsymlinks:native' # Enable native Windows symlink
$env:CCACHE_BASEDIR = "$env:CI_PROJECT_DIR"
$env:CCACHE_DIR = "$env:CCACHE_BASEDIR/ccache"
$env:CCACHE_MAXSIZE = "500M"
$env:CCACHE_DEPEND = 1 # cache misses are too expensive with preprocessor mode
$env:CC = "ccache gcc"
mkdir build
cd build
D:\a\dingusppc\dingusppc\msys64\usr\bin\bash -lc "ccache --zero-stats"
D:\a\dingusppc\dingusppc\msys64\usr\bin\bash -lc "cmake -DCMAKE_BUILD_TYPE=Release -DPPC_BUILD_PPC_TESTS=True .. && ninja"
D:\a\dingusppc\dingusppc\msys64\usr\bin\bash -lc "ccache --show-stats"
Write-Output "Finished build at $(Get-Date -Format u)"
ctest --output-on-failure --parallel
- name: Upload logs on failure
if: failure()
uses: actions/upload-artifact@v6
with:
name: logs-${{ github.job }}
path: |
${{ github.workspace }}/build/Testing/Temporary/LastTest.log
${{ github.workspace }}/build/CMakeFiles/CMakeOutput.log
${{ github.workspace }}/build/CMakeFiles/CMakeError.log
if-no-files-found: ignore
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
- name: Upload artifact
if: always()
uses: actions/upload-artifact@v6
with:
name: DingusPPC-MSYS
path: ${{github.workspace}}/build/bin
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
vsbuild-CLANG:
build-windows-vsbuild:
runs-on: windows-latest
timeout-minutes: 45
env:
VCPKG_FEATURE_FLAGS: binarycaching
strategy:
fail-fast: false
matrix:
include:
- name: clang
generator: Ninja
cmake_args: -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl
ccache_args: -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
upload_suffix: CLANG
- name: msvc
generator: Ninja
cmake_args: ""
ccache_args: -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
upload_suffix: MSVC
- name: msbuild
generator: "Visual Studio 17 2022"
cmake_args: ""
ccache_args: ""
upload_suffix: MSBUILD
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v5
with:
submodules: recursive
- name: Setup msbuild
if: inputs.configuration != 'CMake'
uses: microsoft/setup-msbuild@v1
- name: Setup VCPKG
run: |
vcpkg integrate install
vcpkg install pthread:x64-windows
vcpkg install pthreads:x64-windows
vcpkg install pthread-stubs:x64-windows
vcpkg install pthreadpool:x64-windows
vcpkg install
- name: init_submodules
run: git submodule update --init --recursive
- name: Build
uses: microsoft/setup-msbuild@v3
- name: Install vcpkg packages
shell: cmd
run: '"%VCPKG_INSTALLATION_ROOT%\vcpkg.exe" install --triplet x64-windows'
- name: Install Ninja
if: matrix.generator == 'Ninja'
run: choco install ninja -y
- name: Cache ccache
if: matrix.generator == 'Ninja'
uses: actions/cache@v5
with:
path: ${{ github.workspace }}/.ccache/vsbuild-${{ matrix.name }}
key: vsbuild-${{ matrix.name }}-ccache-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: vsbuild-${{ matrix.name }}-ccache-${{ env.BUILD_TYPE }}-
- name: Install ccache
if: matrix.generator == 'Ninja'
run: choco install ccache -y
- name: Configure & Build
shell: cmd
env:
CCACHE_DIR: ${{ github.workspace }}/.ccache/vsbuild-${{ matrix.name }}
CCACHE_BASEDIR: ${{ github.workspace }}
run: |
mkdir build
cd build
call "%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DPPC_BUILD_PPC_TESTS=True -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows ..
nmake
- name: Upload artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: DingusPPC-CLANG
path: ${{github.workspace}}/build/bin
vsbuild-MSVC:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: Setup msbuild
if: inputs.configuration != 'CMake'
uses: microsoft/setup-msbuild@v1
- name: Setup VCPKG
run: |
vcpkg integrate install
vcpkg install pthread:x64-windows
vcpkg install pthreads:x64-windows
vcpkg install pthread-stubs:x64-windows
vcpkg install pthreadpool:x64-windows
vcpkg install
- name: init_submodules
run: git submodule update --init --recursive
- name: Build
cmake -S . -B build -G "${{ matrix.generator }}" -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DDPPC_68K_DEBUGGER=ON -DDPPC_BUILD_PPC_TESTS=ON ${{ matrix.ccache_args }} -DCMAKE_TOOLCHAIN_FILE=%VCPKG_INSTALLATION_ROOT%/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows ${{ matrix.cmake_args }}
cmake --build build --config ${{ env.BUILD_TYPE }} --parallel
- name: ccache stats
if: matrix.generator == 'Ninja'
shell: cmd
run: |
mkdir build
cd build
call "%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DPPC_BUILD_PPC_TESTS=True -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows ..
nmake
ccache --show-stats
if %errorlevel% neq 0 echo ccache stats unavailable
- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure
- name: Upload logs on failure
if: failure()
uses: actions/upload-artifact@v6
with:
name: logs-${{ github.job }}-${{ matrix.name }}
path: |
${{ github.workspace }}/build/Testing/Temporary/LastTest.log
${{ github.workspace }}/build/CMakeFiles/CMakeOutput.log
${{ github.workspace }}/build/CMakeFiles/CMakeError.log
if-no-files-found: ignore
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
- name: Upload artifact
if: always()
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v6
with:
name: DingusPPC-MSVC
path: ${{github.workspace}}/build/bin
vsbuild-MSVC-MSBUILD:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: Setup msbuild
if: inputs.configuration != 'CMake'
uses: microsoft/setup-msbuild@v1
- name: Setup VCPKG
run: |
vcpkg integrate install
vcpkg install pthread:x64-windows
vcpkg install pthreads:x64-windows
vcpkg install pthread-stubs:x64-windows
vcpkg install pthreadpool:x64-windows
vcpkg install
- name: init_submodules
run: git submodule update --init --recursive
- name: Build
shell: cmd
run: |
mkdir build
cd build
call "%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
cmake -G "Visual Studio 17 2022" -DCMAKE_BUILD_TYPE=Release -DPPC_BUILD_PPC_TESTS=True -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows ..
msbuild dingusppc.sln
- name: Upload artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: DingusPPC-MSBUILD
name: DingusPPC-${{ matrix.upload_suffix }}
path: ${{github.workspace}}/build/bin
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
+60 -6
View File
@@ -138,6 +138,16 @@ endif()
file(GLOB TEST_SOURCES "${PROJECT_SOURCE_DIR}/cpu/ppc/test/*.cpp")
if (APPLE)
add_executable(dingusppc MACOSX_BUNDLE ${SOURCES}
$<TARGET_OBJECTS:core>
$<TARGET_OBJECTS:cpu_ppc>
$<TARGET_OBJECTS:debugger>
$<TARGET_OBJECTS:devices>
$<TARGET_OBJECTS:machines>
$<TARGET_OBJECTS:utils>
$<TARGET_OBJECTS:loguru>)
else()
add_executable(dingusppc ${SOURCES} $<TARGET_OBJECTS:core>
$<TARGET_OBJECTS:cpu_ppc>
$<TARGET_OBJECTS:debugger>
@@ -145,9 +155,49 @@ add_executable(dingusppc ${SOURCES} $<TARGET_OBJECTS:core>
$<TARGET_OBJECTS:machines>
$<TARGET_OBJECTS:utils>
$<TARGET_OBJECTS:loguru>)
endif()
# 2. Configure Apple-specific Bundle Properties
if (APPLE)
# Identify if we are targeting iOS or macOS
if (IOS)
set(BUNDLE_ID "com.dingusdev.dingusppc-ios")
message(STATUS "Configuring for iOS Bundle")
else()
set(BUNDLE_ID "com.dingusdev.dingusppc")
message(STATUS "Configuring for macOS Bundle")
endif()
set_target_properties(dingusppc PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER "${BUNDLE_ID}"
MACOSX_BUNDLE_BUNDLE_NAME "DingusPPC"
MACOSX_BUNDLE_BUNDLE_VERSION "alpha 1.0.4"
MACOSX_BUNDLE_SHORT_VERSION_STRING "a1.0.4"
MACOSX_BUNDLE_EXECUTABLE_NAME "DingusPPC"
# Placeholder for the icon file:
# MACOSX_BUNDLE_ICON_FILE "icon.icns"
)
find_library(COCOA_LIBRARY Cocoa)
find_library(IOKIT_LIBRARY IOKit)
find_library(COREAUDIO_LIBRARY CoreAudio)
find_library(AUDIOTOOLBOX_LIBRARY AudioToolbox)
target_link_libraries(dingusppc PRIVATE
${COCOA_LIBRARY}
${IOKIT_LIBRARY}
${COREAUDIO_LIBRARY}
${AUDIOTOOLBOX_LIBRARY}
)
if (IOS)
target_link_libraries(dingusppc PRIVATE "-framework Foundation" "-framework UIKit")
endif()
endif()
if (WIN32)
target_link_libraries(dingusppc PRIVATE SDL2::SDL2 SDL2::SDL2main cubeb)
target_link_libraries(dingusppc PRIVATE SDL2::SDL2 cubeb)
target_compile_definitions(dingusppc PRIVATE SDL_MAIN_HANDLED)
elseif (EMSCRIPTEN)
target_link_libraries(dingusppc PRIVATE
${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT}
@@ -159,7 +209,7 @@ elseif (EMSCRIPTEN)
"-s EXPORT_NAME=emulator"
"-s 'EXTRA_EXPORTED_RUNTIME_METHODS=[\"FS\"]'")
else()
target_link_libraries(dingusppc PRIVATE SDL2::SDL2 SDL2::SDL2main cubeb
target_link_libraries(dingusppc PRIVATE SDL2::SDL2main SDL2::SDL2 cubeb
${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
endif()
@@ -183,9 +233,10 @@ if (DPPC_BUILD_PPC_TESTS)
$<TARGET_OBJECTS:loguru>)
if (WIN32)
target_link_libraries(testppc PRIVATE SDL2::SDL2 SDL2::SDL2main cubeb)
target_link_libraries(testppc PRIVATE SDL2::SDL2 cubeb)
target_compile_definitions(testppc PRIVATE SDL_MAIN_HANDLED)
else()
target_link_libraries(testppc PRIVATE SDL2::SDL2 SDL2::SDL2main cubeb
target_link_libraries(testppc PRIVATE SDL2::SDL2main SDL2::SDL2 cubeb
${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
endif()
@@ -208,8 +259,11 @@ if (DPPC_BUILD_BENCHMARKS)
$<TARGET_OBJECTS:utils>
$<TARGET_OBJECTS:loguru>)
target_link_libraries(bench1 PRIVATE cubeb SDL2::SDL2 SDL2::SDL2main ${CMAKE_DL_LIBS}
target_link_libraries(bench1 PRIVATE cubeb SDL2::SDL2 ${CMAKE_DL_LIBS}
${CMAKE_THREAD_LIBS_INIT})
if (WIN32)
target_compile_definitions(bench1 PRIVATE SDL_MAIN_HANDLED)
endif()
if (DPPC_68K_DEBUGGER)
target_link_libraries(bench1 PRIVATE capstone)
@@ -223,7 +277,7 @@ if (DPPC_BUILD_PPC_TESTS)
"${PROJECT_SOURCE_DIR}/cpu/ppc/test/ppcinttests.csv"
"${PROJECT_SOURCE_DIR}/cpu/ppc/test/ppcfloattests.csv"
"${PROJECT_SOURCE_DIR}/cpu/ppc/test/ppcdisasmtest.csv"
$<TARGET_FILE_DIR:${PROJECT_NAME}>)
"$<TARGET_FILE_DIR:$<TARGET_PROPERTY:NAME>>")
endif()
install (TARGETS dingusppc DESTINATION ${PROJECT_SOURCE_DIR}/build)
+14 -12
View File
@@ -4,10 +4,10 @@
## Developers
- divingkatae
- maximumspatium
- joevt
- mihaip
- kkaisershot
- maximumspatium
- mihaip
## NT4/PPC fork
@@ -15,21 +15,23 @@
## DevOps
- Waqar144
- webspacecreations
- leap0x7b
- sdkmap
- alicela1n
- Cacodemon345
- dressupgeekout
- kth5
- dyharlan
- roytam1
- mrpapersonic
- Randrianasulu
- erichelgeson
- jarz
- kth5
- leap0x7b
- lefp
- mathstuf
- mrpapersonic
- Randrianasulu
- roytam1
- sdkmap
- seanm
- erichelgeson
- alicela1n
- Waqar144
- webspacecreations
## Testing
+31 -10
View File
@@ -6,13 +6,17 @@ Be warned the program is highly unfinished and could use a lot of testing. Any f
## Philosophy of Use
While many other PowerPC emus exist (PearPC, Sheepshaver), none of them currently attempt emulation of PowerPC Macs accurately (except for QEMU).
While many other PowerPC emus exist (PearPC, Sheepshaver), none of them currently attempt emulation of PowerPC Macs
accurately (except for QEMU).
This program aims to not only improve upon what Sheepshaver, PearPC, and other PowerPC Mac emulators have done, but also to provide a better debugging environment. This currently is designed to work best with PowerPC NuBus and Old World ROMs, including those of the Power Mac 6100, 7200, and G3 Beige.
This program aims to not only improve upon what Sheepshaver, PearPC, and other PowerPC Mac emulators have done, but
also to provide a better debugging environment. This currently is designed to work best with PowerPC NuBus and Old
World ROMs, including those of the Power Mac 6100, 7200, and G3 Beige.
## Implemented Features
Several machines have been implemented to varying degrees, like many Old World PowerPC Macs, early New World PowerPC Macs, and the Pippin.
Several machines have been implemented to varying degrees, like many Old World PowerPC Macs, early New World
PowerPC Macs, and the Pippin.
This emulator has a debugging environment, complete with a disassembler.
@@ -65,6 +69,7 @@ git clone https://github.com/dingusdev/dingusppc
If this is from a mirror, replace the argument with the source you want to use instead.
You will also have to recursive clone or run
```
git submodule update --init --recursive
```
@@ -77,27 +82,43 @@ For SDL2, Linux users may also have to run:
sudo apt install libsdl2-dev
```
CLI11 and loguru are already included in the thirdparty folder and compiled along with the rest of DingusPPC.
macOS users can use Homebrew or MacPorts to install SDL2.
CLI11 and loguru are already included in the thirdparty folder and compiled along with the rest of DingusPPC.
For Raspbian, you may also need the following command:
```
sudo apt install doxygen graphviz
```
To build the project in a Unix-like environment, create a build folder, change the directory to the build folder,
and use `cmake` to create the `Makefile` files in that build folder.
Use `make` to do the building. You don't need to execute `cmake` again unless you add/remove/change options or
source files.
For example, to build the project in a Unix-like environment, you will need to run
the following commands in the OS terminal:
```
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make dingusppc
make
```
You may specify another build type using the variable CMAKE_BUILD_TYPE.
For Raspbian, you may also need the following command:
You may specify another build type using the variable `CMAKE_BUILD_TYPE`.
Each build type should have its own build folder.
```
sudo apt install doxygen graphviz
mkdir build-debug
cd build-debug
cmake -DCMAKE_BUILD_TYPE=Debug ..
make
```
## Testing
DingusPPC includes a test suite for verifying the correctness of its PowerPC CPU
emulation. To build the tests, use the following terminal commands:
```
mkdir build
cd build
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+5 -5
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -62,8 +62,8 @@ public:
~MouseEvent() = default;
uint32_t flags;
uint32_t xrel;
uint32_t yrel;
int32_t xrel;
int32_t yrel;
uint32_t xabs;
uint32_t yabs;
uint8_t buttons_state;
+5 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -492,6 +492,8 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_l
case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL3):
if (kbd_locale == Jpn_JPN)
return AdbKey_JIS_Yen;
else
return -1;
case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL1):
return AdbKey_JIS_Underscore;
case 0XBC:
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+13 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -156,3 +156,13 @@ uint64_t TimerManager::process_timers()
// return time slice in nanoseconds until next timer's expiry
return cur_timer->timeout_ns - time_now;
}
void TimerManager::cancel_all_timers()
{
std::shared_ptr<TimerInfo> cur_timer;
while (!this->timer_queue.empty()) {
cur_timer = this->timer_queue.top();
LOG_F(WARNING, "Canceling timer id:%u ns:%llu", cur_timer->id, cur_timer->timeout_ns);
this->timer_queue.pop();
}
}
+6 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -51,6 +51,8 @@ class my_priority_queue : public std::priority_queue<T, Container, Compare> {
public:
bool remove_by_id(const uint32_t id){
std::lock_guard<std::recursive_mutex> lk(mtx);
if (this->empty())
return false;
auto el = this->top();
if (el->id == id) {
std::priority_queue<T, Container, Compare>::pop();
@@ -132,6 +134,7 @@ public:
uint32_t add_cyclic_timer(uint64_t interval, timer_cb cb);
uint32_t add_cyclic_timer(uint64_t interval, uint64_t delay, timer_cb cb);
void cancel_timer(uint32_t id);
void cancel_all_timers();
uint64_t process_timers();
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+12 -12
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -259,9 +259,9 @@ const char* spr_index0[32] = {"mq", "xer", "", "", "rtcu", "rtcl", "de
"", "sdr1", "srr0", "srr1", "", "", "", ""};
const char* spr_index8[32] = {
"", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "sprg0", "sprg1", "sprg2", "sprg3", "sprg4", "sprg5",
"sprg6", "sprg7", "", "", "ear", "", "tbl", "tbu", "", "pvr"};
"", "", "", "", "", "", "", "", "", "", "",
"", "tbl_u", "tbu_u", "", "", "sprg0", "sprg1", "sprg2", "sprg3", "sprg4", "sprg5",
"sprg6", "sprg7", "", "", "ear", "", "tbl", "tbu", "", "pvr"};
const char* spr_index16[32] = {
"", "", "", "", "", "", "", "",
@@ -1176,14 +1176,14 @@ void opc_group31(PPCDisasmContext* ctx) {
if (!rs && !ra)
opc_illegal(ctx);
else {
ctx->instr_str = my_sprintf("%-7s r%s", "tlbld", rb);
ctx->instr_str = my_sprintf("%-7s r%d", "tlbld", rb);
add_reg_in(ctx, "r%d", rb);
}
} else if (index == 30) { /* tlbli - 603 only */
} else if (index == 31) { /* tlbli - 603 only */
if (!rs && !ra)
opc_illegal(ctx);
else {
ctx->instr_str = my_sprintf("%-7s r%s", "tlbli", rb);
ctx->instr_str = my_sprintf("%-7s r%d", "tlbli", rb);
add_reg_in(ctx, "r%d", rb);
}
}
@@ -1250,10 +1250,10 @@ void opc_group31(PPCDisasmContext* ctx) {
add_reg_out(ctx, "cr");
}
} else {
strcpy(opcode, opc_logic[index]);
if (!strlen(opcode)) {
if (index >= 16 || !strlen(opc_logic[index])) {
opc_illegal(ctx);
} else {
strcpy(opcode, opc_logic[index]);
if (rc_set) {
strcat(opcode, ".");
add_reg_out(ctx, "cr");
@@ -1394,9 +1394,9 @@ void opc_group31(PPCDisasmContext* ctx) {
break;
}
auto ref_spr = (((ctx->instr_code >> 11) & 31) << 5) | ((ctx->instr_code >> 16) & 31);
auto spr_high = (ctx->instr_code >> 11) & 31;
auto spr_low = (ctx->instr_code >> 16) & 31;
auto ref_spr = (spr_high << 5) | spr_low;
switch (ext_opc) {
case 0: /* cmp */
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+4 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -106,6 +106,7 @@ enum SPR : int {
SPRG1 = 273,
SPRG2 = 274,
SPRG3 = 275,
EAR = 282,
TBL_S = 284, // supervisor TBL
TBU_S = 285, // supervisor TBU
PVR = 287,
+5 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -161,6 +161,8 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
exc_descriptor = "DSI/ISI exception: unmapped memory access";
else if (ppc_state.spr[SPR::DSISR] & 0x08000000)
exc_descriptor = "DSI/ISI exception: access protection violation";
else if (ppc_state.spr[SPR::DSISR] & 0x00100000)
exc_descriptor = "DSI exception: External access is disabled";
else {
if (exception_type == Except_Type::EXC_DSI)
exc_descriptor = "DSI exception";
+5 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -901,6 +901,8 @@ static map<string, int> SPRName2Num = {
{"MMCR0", SPR::MMCR0}, {"PMC1", SPR::PMC1}, {"PMC2", SPR::PMC2},
{"SDA", SPR::SDA}, {"SIA", SPR::SIA}, {"MMCR1", SPR::MMCR1},
{"PMC3", SPR::PMC3}, {"PMC4", SPR::PMC4},
// get value from supervisor index same as we do for SPR268 and SPR269
{"TBL_U", SPR::TBL_S}, {"TBU_U", SPR::TBU_S},
};
static uint64_t reg_op(string& reg_name, uint64_t val, bool is_write) {
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+7 -7
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -72,7 +72,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
int reg_a = (opcode >> 16) & 31; \
int reg_b = (opcode >> 11) & 31; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
#define ppc_grab_regssab(opcode) \
int reg_s = (opcode >> 21) & 31; \
@@ -87,13 +87,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
int reg_a = (opcode >> 16) & 31; \
int reg_b = (opcode >> 11) & 31; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
#define ppc_grab_regsab(opcode) \
int reg_a = (opcode >> 16) & 31;\
int reg_b = (opcode >> 11) & 31;\
uint32_t ppc_result_a = ppc_state.gpr[reg_a];\
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
#define ppc_grab_regssa(opcode) \
int reg_s = (opcode >> 21) & 31; \
@@ -151,7 +151,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
int reg_b = (opcode >> 11) & 31;
#define GET_FPR(reg) \
ppc_state.fpr[(reg)].dbl64_r
ppc_state.fpr[(reg)].dbl64_r
#define FPR_INT(reg) \
ppc_state.fpr[reg].int64_r
+6 -6
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -171,9 +171,9 @@ static inline uint8_t* calc_pteg_addr(uint32_t hash)
sdr1_val = ppc_state.spr[SPR::SDR1];
pteg_addr = sdr1_val & 0xFE000000;
pteg_addr |= (sdr1_val & 0x01FF0000) | (((sdr1_val & 0x1FF) << 16) & ((hash & 0x7FC00) << 6));
pteg_addr |= (hash & 0x3FF) << 6;
pteg_addr = (sdr1_val & 0xFFFF0000) |
(((sdr1_val & 0x1FF) << 16) & ((hash & 0x7FC00) << 6)) |
((hash & 0x3FF) << 6);
if (pteg_addr >= last_ptab_area.start && pteg_addr <= last_ptab_area.end) {
return last_ptab_area.mem_ptr + (pteg_addr - last_ptab_area.start);
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+53 -21
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -879,13 +879,11 @@ static void update_timebase(uint64_t mask, uint64_t new_val)
tbr_wr_timestamp = get_virt_time_ns();
}
static uint32_t decrementer_timer_id = 0;
static void update_decrementer(bool update_time_stamp, uint32_t oldval, uint32_t newval);
static void trigger_decrementer_exception() {
decrementer_timer_id = 0;
dec_wr_value = -1;
dec_wr_timestamp = get_virt_time_ns();
if (ppc_state.msr & MSR::EE) {
dec_exception_pending = false;
//LOG_F(WARNING, "decrementer exception triggered");
@@ -897,27 +895,58 @@ static void trigger_decrementer_exception() {
}
}
static void update_decrementer(uint32_t val) {
dec_wr_value = val;
dec_wr_timestamp = get_virt_time_ns();
static void trigger_timed_decrementer_exception() {
decrementer_timer_id = 0;
uint32_t new_val = calc_dec_value();
if (new_val >= 0 && new_val != uint32_t(-1)) {
new_val = -1;
}
update_decrementer(true, new_val, new_val);
trigger_decrementer_exception();
}
static void trigger_immediate_decrementer_exception() {
decrementer_timer_id = 0;
update_decrementer(false, ppc_state.spr[SPR::DEC_S], ppc_state.spr[SPR::DEC_S]);
trigger_decrementer_exception();
}
static void update_decrementer(bool update_time_stamp, uint32_t oldval, uint32_t newval) {
if (update_time_stamp) {
dec_wr_value = newval;
dec_wr_timestamp = get_virt_time_ns();
}
dec_exception_pending = false;
if (is_601)
return;
if (decrementer_timer_id) {
//LOG_F(WARNING, "decrementer cancel timer");
TimerManager::get_instance()->cancel_timer(decrementer_timer_id);
}
if (bit_changed(oldval, newval, 31) && bit_set(newval, 31)) {
decrementer_timer_id = TimerManager::get_instance()->add_immediate_timer(
trigger_immediate_decrementer_exception
);
return;
}
// A count of zero should timeout after one tick so add one to the count
// but make sure the count doesn't overflow.
if (is_601) {
if (newval < uint32_t(-0x80))
newval += 0x80;
} else {
if (newval < uint32_t(-1))
newval += 1;
}
uint64_t time_out;
uint32_t time_out_lo;
_u32xu64(val, tbr_period_ns, time_out, time_out_lo);
//LOG_F(WARNING, "decrementer:0x%08X ns:%llu", val, time_out);
_u32xu64(newval, tbr_period_ns, time_out, time_out_lo);
//LOG_F(WARNING, "new decrementer value: 0x%08X, interrupt after %llu ns", newval, time_out);
decrementer_timer_id = TimerManager::get_instance()->add_oneshot_timer(
time_out,
trigger_decrementer_exception
trigger_timed_decrementer_exception
);
}
@@ -973,6 +1002,7 @@ void dppc_interpreter::ppc_mfspr(uint32_t opcode) {
ppc_state.gpr[reg_d] = ppc_state.spr[SPR::DEC_S] = val;
break;
}
case SPR::TBL_U:
case SPR::TBL_S: {
uint64_t tbr_value = calc_tbr_value();
ppc_state.gpr[reg_d] =
@@ -980,6 +1010,7 @@ void dppc_interpreter::ppc_mfspr(uint32_t opcode) {
ppc_state.spr[TBU_S] = uint32_t(tbr_value >> 32);
break;
}
case SPR::TBU_U:
case SPR::TBU_S: {
uint64_t tbr_value = calc_tbr_value();
ppc_state.gpr[reg_d] =
@@ -1045,8 +1076,8 @@ void dppc_interpreter::ppc_mtspr(uint32_t opcode) {
case SPR::DEC_S:
if (is_601)
val &= ~0x7F;
ppc_state.spr[DEC_S] = val;
update_decrementer(val);
update_decrementer(true, calc_dec_value(), val);
ppc_state.spr[SPR::DEC_S] = val;
break;
case SPR::TBL_S:
update_timebase(0xFFFFFFFF00000000ULL, val);
@@ -2010,7 +2041,7 @@ void dppc_interpreter::ppc_eciwx(uint32_t opcode) {
uint32_t ear_enable = 0x80000000;
// error if EAR[E] != 1
if (!(ppc_state.spr[282] && ear_enable)) {
if (!(ppc_state.spr[SPR::EAR] & ear_enable)) {
ppc_exception_handler(Except_Type::EXC_DSI, 0x0);
}
@@ -2030,7 +2061,8 @@ void dppc_interpreter::ppc_ecowx(uint32_t opcode) {
uint32_t ear_enable = 0x80000000;
// error if EAR[E] != 1
if (!(ppc_state.spr[282] && ear_enable)) {
if (!(ppc_state.spr[SPR::EAR] & ear_enable)) {
ppc_state.spr[SPR::DSISR] = 0x00100000;
ppc_exception_handler(Except_Type::EXC_DSI, 0x0);
}
+4
View File
@@ -407,6 +407,10 @@
0xFFF00100,0x7D453D2A,stswx,r10,r5,r7
0xFFF00100,0x7C0002E4,tlbia
0xFFF00100,0x7C004A64,tlbie,r9
0xFFF00100,0x7C202FA4,tlbld,r5
0xFFF00100,0x7C6007A4,tlbld,r0
0xFFF00100,0x7C203FE4,tlbli,r7
0xFFF00100,0x7C40FFE4,tlbli,r31
# various simplified (extended) mnemonics
0xFFF00100,0x60000000,nop
1 # Test data for PowerPC disassembler supplied as comma-separated values
407 0xFFF00100,0x7C430C32,rrib,r3,r2,r1 0xFFF00100,0x7C00003A,maskg,r0,r0,r0
408 0xFFF00100,0x7C430C33,rrib.,r3,r2,r1 0xFFF00100,0x7E3EE43A,maskir,r30,r17,r28
409 0xFFF00100,0x7C410132,sle,r1,r2,r0 0xFFF00100,0x58411800,rlmi,r1,r2,r3,0,0
410 0xFFF00100,0x58411801,rlmi.,r1,r2,r3,0,0
411 0xFFF00100,0x7C430C32,rrib,r3,r2,r1
412 0xFFF00100,0x7C430C33,rrib.,r3,r2,r1
413 0xFFF00100,0x7C410132,sle,r1,r2,r0
414 0xFFF00100,0x7C410133,sle.,r1,r2,r0
415 0xFFF00100,0x7C4101B2,sleq,r1,r2,r0
416 0xFFF00100,0x7C4101B3,sleq.,r1,r2,r0
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+48 -9
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -425,21 +425,54 @@ static void patch_mem(string& params) {
}
}
static uint32_t disasm(PPCDisasmContext &ctx) {
ctx.instr_code = READ_DWORD_BE_A(mmu_translate_imem(ctx.instr_addr));
cout << COUT08X << ctx.instr_addr;
cout << ": " << COUT08X << ctx.instr_code;
cout << " " << disassemble_single(&ctx) << setfill(' ') << right << dec;
return ctx.instr_addr;
}
static uint32_t disasm(uint32_t count, uint32_t address) {
PPCDisasmContext ctx;
ctx.instr_addr = address;
ctx.simplified = true;
for (int i = 0; power_on && i < count; i++) {
ctx.instr_code = READ_DWORD_BE_A(mmu_translate_imem(ctx.instr_addr));
cout << COUT08X << ctx.instr_addr;
cout << ": " << COUT08X << ctx.instr_code;
cout << " " << disassemble_single(&ctx) << setfill(' ') << right << endl;
disasm(ctx);
cout << endl;
}
return ctx.instr_addr;
}
static void disasm_in(PPCDisasmContext &ctx, uint32_t address) {
ctx.instr_addr = address;
ctx.simplified = true;
disasm(ctx);
if (ctx.regs_in.size() > 0 || ctx.regs_out.size() > 0) {
if (ctx.instr_str.length() < 28)
cout << setw(28 - (int)ctx.instr_str.length()) << " ";
cout << " ;";
if (ctx.regs_in.size() > 0) {
cout << " in{" << COUTX;
for (auto & reg_name : ctx.regs_in) {
cout << " " << reg_name << ":" << get_reg(reg_name);
}
cout << " }" << dec;
}
}
}
static void disasm_out(PPCDisasmContext &ctx) {
if (ctx.regs_out.size() > 0) {
cout << " out{" << COUTX;
for (auto & reg_name : ctx.regs_out) {
cout << " " << reg_name << ":" << get_reg(reg_name);
}
cout << " }" << dec;
}
cout << endl;
}
static void print_gprs() {
string reg_name;
int i;
@@ -753,6 +786,9 @@ void DppcDebugger::enter_debugger() {
delete_prompt();
}
for (; --count >= 0;) {
addr_str = "R24";
addr = static_cast<uint32_t>(get_reg(addr_str) - 2);
disasm_68k(1, addr);
exec_single_68k();
}
#endif
@@ -762,7 +798,10 @@ void DppcDebugger::enter_debugger() {
}
for (; --count >= 0;) {
addr = ppc_state.pc;
PPCDisasmContext ctx;
disasm_in(ctx, addr);
ppc_exec_single();
disasm_out(ctx);
}
}
} else if (cmd == "next" || cmd == "ni") {
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+10 -10
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -35,9 +35,9 @@ void AdbAppleJack::event_handler(const GamepadEvent& event) {
uint32_t button_bit = 1 << event.button;
if (event.flags & GAMEPAD_EVENT_DOWN)
this->buttons_state |= button_bit;
this->aj_buttons_state |= button_bit;
else if (event.flags & GAMEPAD_EVENT_UP)
this->buttons_state &= ~button_bit;
this->aj_buttons_state &= ~button_bit;
if (button_bit & ((1 << GamepadButton::LeftTrigger) | (1 << GamepadButton::RightTrigger)))
this->triggers_changed = true;
@@ -47,7 +47,7 @@ void AdbAppleJack::event_handler(const GamepadEvent& event) {
void AdbAppleJack::reset() {
this->AdbMouse::reset();
this->buttons_state = 0;
this->aj_buttons_state = 0;
this->triggers_changed = false;
this->buttons_changed = false;
LOG_F(INFO, "%s: reset; in mouse emulation mode", this->name.c_str());
@@ -58,16 +58,16 @@ bool AdbAppleJack::get_register_0() {
uint8_t mouse_buttons = this->AdbMouse::get_buttons_state();
// AppleJack triggers always affect the mouse button bits.
mouse_buttons |= (this->buttons_state >> (GamepadButton::LeftTrigger - 0)) & 1;
mouse_buttons |= (this->buttons_state >> (GamepadButton::RightTrigger - 1)) & 2;
mouse_buttons |= (this->aj_buttons_state >> (GamepadButton::LeftTrigger - 0)) & 1;
mouse_buttons |= (this->aj_buttons_state >> (GamepadButton::RightTrigger - 1)) & 2;
changed |= this->AdbMouse::get_register_0(mouse_buttons, changed);
this->triggers_changed = false;
if (this->dev_handler_id == APPLEJACK_HANDLER_ID && this->buttons_changed) {
uint8_t* out_buf = this->host_obj->get_output_buf();
out_buf[2] = ~this->buttons_state >> 8;
out_buf[3] = ~this->buttons_state & 0xFF;
out_buf[2] = uint8_t(~this->aj_buttons_state >> 8);
out_buf[3] = ~this->aj_buttons_state & 0xFF;
this->host_obj->set_output_count(4);
this->buttons_changed = false;
+4 -4
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -52,7 +52,7 @@ public:
void set_register_3() override;
private:
uint32_t buttons_state = 0;
uint32_t aj_buttons_state = 0;
bool triggers_changed = false;
bool buttons_changed = false;
};
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+4 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -38,6 +38,7 @@ enum {
ADB_STAT_SRQ_ACTIVE = 1 << 0,
ADB_STAT_TIMEOUT = 1 << 1,
ADB_STAT_AUTOPOLL = 1 << 6,
ADB_STAT_RESPONSE = 1 << 7,
};
class AdbDevice; // forward declaration to prevent compiler errors
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+5 -4
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -67,7 +67,8 @@ protected:
virtual void set_register_3() {}
uint8_t exc_event_flag = 0;
uint8_t srq_flag = 0;
uint8_t srq_flag = 0;
uint8_t led_state = 0;
uint8_t my_addr = 0;
uint8_t dev_handler_id = 0;
bool got_collision = false;
+39 -12
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -35,13 +35,18 @@ AdbKeyboard::AdbKeyboard(std::string name) : AdbDevice(name) {
void AdbKeyboard::event_handler(const KeyboardEvent& event) {
this->pending_events.push_back(std::make_unique<KeyboardEvent>(event));
if (this->pending_events.size() == 1) {
this->srq_flag = 1;
}
}
void AdbKeyboard::reset() {
this->my_addr = ADB_ADDR_KBD;
this->dev_handler_id = 2; // Extended ADB keyboard
this->exc_event_flag = 1;
this->srq_flag = 1; // enable service requests
this->srq_flag = 0; // don't process keyboard service requests yet
this->led_state = 0; // LEDs off
this->pending_events.clear();
}
@@ -53,6 +58,11 @@ bool AdbKeyboard::get_register_0() {
out_buf[0] = this->consume_pending_event();
out_buf[1] = this->consume_pending_event();
this->host_obj->set_output_count(2);
if (this->pending_events.empty()) {
this->srq_flag = 0;
}
return true;
}
@@ -68,14 +78,7 @@ uint8_t AdbKeyboard::consume_pending_event() {
std::unique_ptr<KeyboardEvent> event = std::move(this->pending_events.front());
this->pending_events.pop_front();
uint8_t key_state = 0;
if (event->flags & KEYBOARD_EVENT_DOWN) {
key_state = 0;
} else if (event->flags & KEYBOARD_EVENT_UP) {
key_state = 1;
} else {
LOG_F(WARNING, "%s: unknown keyboard event flags %x", this->name.c_str(), event->flags);
}
uint8_t key_state = (event->flags & KEYBOARD_EVENT_UP) ? 1 : 0;
if (this->dev_handler_id != 3) {
switch (event->key) {
@@ -88,7 +91,31 @@ uint8_t AdbKeyboard::consume_pending_event() {
return (key_state << 7) | (event->key & 0x7F);
}
bool AdbKeyboard::get_register_2() {
uint8_t* out_buf = this->host_obj->get_output_buf();
out_buf[0] = 0;
out_buf[1] = this->led_state & 0x07;
this->host_obj->set_output_count(2);
return true;
}
void AdbKeyboard::set_register_2() {
if (this->host_obj->get_input_count() < 2)
return;
const uint8_t* in_data = this->host_obj->get_input_buf();
this->led_state = in_data[1] & 0x07;
}
bool AdbKeyboard::get_register_3() {
uint8_t* out_buf = this->host_obj->get_output_buf();
out_buf[0] = (this->my_addr << 4) | (1 << 1) | 1; // Address + SRQ Enable + Exc Event
out_buf[1] = this->dev_handler_id;
this->host_obj->set_output_count(2);
return true;
}
void AdbKeyboard::set_register_3() {
+5 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -46,6 +46,8 @@ public:
void event_handler(const KeyboardEvent& event);
bool get_register_0() override;
bool get_register_2() override;
bool get_register_3() override;
void set_register_2() override;
void set_register_3() override;
+6 -6
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -66,7 +66,7 @@ void AdbMouse::reset() {
this->changed = false;
}
bool AdbMouse::get_register_0(uint8_t buttons_state, bool force) {
bool AdbMouse::get_register_0(uint8_t buttons, bool force) {
bool should_update = this->x_rel || this->y_rel || this->changed || force;
if (should_update) {
@@ -84,7 +84,7 @@ bool AdbMouse::get_register_0(uint8_t buttons_state, bool force) {
num_bits = this->num_bits;
total_bits = std::max(buttons_to_bits[this->num_buttons], bits_to_bits[num_bits]);
}
uint8_t buttons_state = ~this->buttons_state;
buttons = ~buttons;
for (int axis = 0; axis < 2; axis++) {
int bits = num_bits;
@@ -100,7 +100,7 @@ bool AdbMouse::get_register_0(uint8_t buttons_state, bool force) {
bits = 7;
while (bits_remaining > 0) {
*p = (val & ((1 << bits) - 1)) | (((buttons_state >> button) & 1) << bits) | (*p << (bits + 1));
*p = uint8_t((val & ((1 << bits) - 1)) | (((buttons >> button) & 1) << bits) | (*p << (bits + 1)));
val >>= bits;
bits_remaining -= bits;
p = bits == 7 ? &out_buf[2] : p + 1;
+4 -4
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -70,7 +70,7 @@ enum DeviceClass {
void set_register_3() override;
protected:
bool get_register_0(uint8_t buttons_state, bool force);
bool get_register_0(uint8_t buttons, bool force);
uint8_t get_buttons_state() const;
private:
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+8 -8
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -116,7 +116,7 @@ void AtapiCdrom::perform_packet_command() {
this->status_good();
this->present_status();
break;
case ScsiCommand::READ_CAPACITY_10:
case ScsiCommand::READ_CAPACITY:
this->xfer_cnt = this->report_capacity(this->data_buf);
this->r_byte_count = this->xfer_cnt;
this->data_ptr = (uint16_t*)this->data_buf;
@@ -395,11 +395,11 @@ uint16_t AtapiCdrom::get_data() {
if (this->current_block_byte >= area_start && this->current_block_byte < area_end) {
AddrMsf msf = lba_to_msf(this->current_block + 150);
uint8_t header[4]{
(uint8_t)msf.min,
(uint8_t)msf.sec,
(uint8_t)msf.frm,
(uint8_t)msf.min,
(uint8_t)msf.sec,
(uint8_t)msf.frm,
0x01 // Mode 1
};
};
ret_data = BYTESWAP_16(*((uint16_t*)(&header[current_block_byte - area_start])));
}
}
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+4 -4
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -37,7 +37,7 @@ using namespace MeshScsi;
int MeshController::device_postinit() {
this->bus_obj = dynamic_cast<ScsiBus*>(gMachineObj->get_comp_by_name("ScsiMesh"));
if (bus_obj) {
bus_obj->register_device(7, static_cast<ScsiDevice*>(this));
bus_obj->register_device(7, static_cast<ScsiPhysDevice*>(this));
bus_obj->attach_scsi_devices("2");
}
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+6 -8
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -33,7 +33,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes>
#include <cstring>
Sc53C94::Sc53C94(uint8_t chip_id, uint8_t my_id) : ScsiDevice("SC53C94", my_id), DmaDevice()
Sc53C94::Sc53C94(uint8_t chip_id, uint8_t my_id) : ScsiPhysDevice("SC53C94", my_id), DmaDevice()
{
this->chip_id = chip_id;
this->my_bus_id = my_id;
@@ -45,7 +45,7 @@ int Sc53C94::device_postinit()
{
ScsiBus* bus = dynamic_cast<ScsiBus*>(gMachineObj->get_comp_by_name("ScsiCurio"));
if (bus) {
bus->register_device(7, static_cast<ScsiDevice*>(this));
bus->register_device(7, static_cast<ScsiPhysDevice*>(this));
bus->attach_scsi_devices("");
}
@@ -560,7 +560,6 @@ void Sc53C94::sequencer()
this->bus_obj->target_xfer_data();
break;
case SeqState::CMD_COMPLETE:
this->int_status = INTSTAT_SR | INTSTAT_SO;
this->cur_state = SeqState::IDLE;
this->update_irq();
exec_next_command();
@@ -583,7 +582,6 @@ void Sc53C94::sequencer()
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();
if (!(this->is_dma_cmd)) {
@@ -627,7 +625,6 @@ void Sc53C94::sequencer()
break;
case SeqState::RCV_STATUS:
case SeqState::RCV_MESSAGE:
this->bus_obj->negotiate_xfer(this->data_fifo_pos, this->bytes_out);
this->rcv_data();
if (this->is_initiator) {
if (this->cur_state == SeqState::RCV_STATUS) {
@@ -640,6 +637,7 @@ void Sc53C94::sequencer()
} else if (this->cur_state == SeqState::RCV_MESSAGE) {
this->bus_obj->assert_ctrl_line(this->my_bus_id, SCSI_CTRL_ACK);
if (this->cur_cmd == CMD_COMPLETE_STEPS) {
this->int_status = INTSTAT_SO;
this->cur_state = SeqState::CMD_COMPLETE;
this->sequencer();
}
+5 -7
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -194,7 +194,7 @@ typedef struct {
typedef std::function<void(const uint8_t drq_state)> DrqCb;
class Sc53C94 : public ScsiDevice, public DmaDevice {
class Sc53C94 : public ScsiPhysDevice, public DmaDevice {
public:
Sc53C94(uint8_t chip_id=12, uint8_t my_id=7);
~Sc53C94() = default;
@@ -234,10 +234,8 @@ public:
this->drq_cb = cb;
}
// ScsiDevice methods
// ScsiPhysDevice methods
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 {}
+109 -36
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -25,6 +25,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#define SCSI_H
#include <devices/common/hwcomponent.h>
#include <devices/common/scsi/scsiphysinterface.h>
#include <array>
#include <cinttypes>
@@ -120,7 +121,7 @@ enum ScsiCommand : uint8_t {
DIAG_RESULTS = 0x1C,
SEND_DIAGS = 0x1D,
PREVENT_ALLOW_MEDIUM_REMOVAL = 0x1E,
READ_CAPACITY_10 = 0x25,
READ_CAPACITY = 0x25,
READ_10 = 0x28,
WRITE_10 = 0x2A,
SEEK_10 = 0x2B,
@@ -143,15 +144,9 @@ enum ScsiCommand : uint8_t {
READ_TOC = 0x43,
SET_CD_SPEED = 0xBB,
READ_CD = 0xBE,
// vendor specific commands
VENDOR_09 = 0x09,
EJECT = 0xC0,
READ_CDDA = 0xD8, //TOSHIBA
READ_CDDA_MSF = 0xD9, //TOSHIBA
};
enum ScsiSense : int {
enum ScsiSense : uint8_t {
NO_SENSE = 0x0,
RECOVERED = 0x1,
NOT_READY = 0x2,
@@ -166,7 +161,7 @@ enum ScsiSense : int {
COMPLETED = 0xF
};
enum ScsiError : int {
enum ScsiError : uint8_t {
NO_ERROR = 0x00,
NO_SECTOR = 0x01,
WRITE_FAULT = 0x03,
@@ -180,6 +175,57 @@ enum ScsiError : int {
MEDIUM_NOT_PRESENT = 0x3A,
};
/** SCSI device types used in INQUIRY. */
namespace ScsiDevType {
enum : uint8_t {
DIRECT_ACCESS = 0,
SEQ_ACCESS = 1,
PRINTER = 2,
PROCESSOR = 3,
WRITE_ONCE = 4,
CD_ROM = 5,
SCANNER = 6,
OPT_MEMORY = 7,
MEDIUM_CHANGER = 8,
COMMUNICATION = 9,
UNKNOWN = 0x1F
};
};
/** SCSI device capacity flags. */
enum : uint8_t {
CAP_REL_ADDR = 1 << 7, // device supports relative addressing
CAP_W32_XFER = 1 << 6, // device supports 32-bit wide transfers
CAP_W16_XFER = 1 << 5, // device supports 16-bit wide transfers
CAP_SYNC_XFER = 1 << 4, // device supports synchronous transfers
CAP_LINKED_CMDS = 1 << 3, // device supports linked commands
CAP_CMD_QUEUE = 1 << 1, // device supports command queuing
CAP_CMD_SRST = 1 << 0, // device supports soft resets
};
/** Page control values for MODE SENSE. */
namespace PageControl {
enum : uint8_t {
CURRENT_VALUES = 0,
CHANGEABLE_VALUES = 1,
DEFAULT_VALUES = 2,
SAVED_VALUES = 3
};
};
/** Page numbers for MODE SENSE and MODE SELECT. */
enum ModePage : uint8_t {
ERROR_RECOVERY = 0x1,
DEV_FORMAT_PARAMS = 0x3,
RIGID_DISK_GEOMETRY = 0x4,
CDROM_PARAMS = 0xD,
CDROM_AUDIO = 0xE,
POWER_CONDITION = 0x1A,
CDROM_CAPABILITIES = 0x2A,
VENDOR_PAGE_31 = 0x31,
ALL_PAGES = 0x3F,
};
/** Standard SCSI bus timing values measured in ns. */
constexpr uint64_t BUS_SETTLE_DELAY = 400;
constexpr uint64_t BUS_FREE_DELAY = 800;
@@ -192,34 +238,65 @@ constexpr auto SCSI_MAX_DEVS = 8;
class ScsiBus;
typedef std::function<void()> action_callback;
class ScsiDevice : public HWComponent {
class ScsiPhysDevice : public ScsiPhysInterface, public HWComponent {
public:
ScsiDevice(std::string name, int my_id) {
ScsiPhysDevice(std::string name, int my_id) : ScsiPhysInterface(PHY_ID_SCSI) {
this->set_name(name);
supports_types(HWCompType::SCSI_DEV);
this->scsi_id = my_id;
this->lun = 0,
this->cur_phase = ScsiPhase::BUS_FREE;
}
~ScsiDevice() = default;
~ScsiPhysDevice() = default;
// ScsiPhysInterface methods
bool last_sel_has_attention() override {
return this->last_selection_has_attention;
}
uint8_t last_sel_msg() override {
return this->last_selection_message;
}
void set_xfer_len(uint64_t len) override {
this->xfer_len = len;
}
void set_buffer(uint8_t *bptr) override {
this->buf_ptr = bptr;
}
void set_read_more_data_cb(more_data_cb_t cb) override {
this->read_more_data = cb;
}
void set_write_more_data_cb(more_data_cb_t cb) override {
this->write_more_data = cb;
}
void set_post_xfer_action(action_callback cb) override {
this->post_xfer_action = cb;
}
void set_status(uint8_t status_code) override {
this->status = status_code;
}
void set_eject_state(bool eject_allowed) override {
this->eject_allowed = eject_allowed;
}
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 void prepare_xfer();
virtual void switch_phase(const int new_phase) override;
virtual bool allow_phase_change();
virtual bool has_data() { return this->data_size != 0; }
virtual int xfer_data();
virtual int send_data(uint8_t* dst_ptr, int count);
virtual int rcv_data(const uint8_t* src_ptr, const int count);
virtual bool check_lun();
void illegal_command(const uint8_t* cmd);
virtual bool prepare_data() = 0;
virtual bool get_more_data() = 0;
virtual void process_command() = 0;
virtual void process_message();
@@ -227,8 +304,6 @@ public:
this->bus_obj = bus_obj_ptr;
}
void report_error(uint8_t sense_key, uint8_t asc);
protected:
uint8_t cmd_buf[16] = {};
uint8_t msg_buf[16] = {}; // TODO: clarify how big this one should be
@@ -237,18 +312,14 @@ protected:
int initiator_id;
int cur_phase;
uint8_t* data_ptr = nullptr;
uint8_t* buf_ptr = nullptr;
int xfer_len;
int data_size;
int incoming_size;
uint8_t status;
int sense;
int asc;
int ascq;
int sksv;
int field;
bool valid;
bool last_selection_has_atention = false;
bool eject_allowed = true;
bool last_selection_has_attention = false;
uint8_t last_selection_message = 0;
ScsiBus* bus_obj;
@@ -256,6 +327,9 @@ protected:
action_callback pre_xfer_action = nullptr;
action_callback post_xfer_action = nullptr;
more_data_cb_t read_more_data = {};
more_data_cb_t write_more_data = {};
};
/** This class provides a higher level abstraction for the SCSI bus. */
@@ -275,7 +349,7 @@ public:
void attach_scsi_devices(const std::string bus_suffix);
// low-level state management
void register_device(int id, ScsiDevice* dev_obj);
void register_device(int id, ScsiPhysDevice* dev_obj);
int current_phase() const {
return this->cur_phase;
@@ -310,14 +384,13 @@ public:
bool push_data(const int id, const uint8_t* src_ptr, const int size);
int target_xfer_data();
void target_next_step();
bool negotiate_xfer(int& bytes_in, int& bytes_out);
protected:
void change_bus_phase(int initiator_id);
private:
// SCSI devices registered with this bus
std::array<ScsiDevice*, SCSI_MAX_DEVS> devices;
std::array<ScsiPhysDevice*, SCSI_MAX_DEVS> devices;
// per-device state of the control lines
uint16_t dev_ctrl_lines[SCSI_MAX_DEVS] = {};
+259
View File
@@ -0,0 +1,259 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
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/>.
*/
#include <devices/common/scsi/scsiblockcmds.h>
#include <loguru.hpp>
#include <memaccess.h>
ScsiBlockCmds::ScsiBlockCmds(int cache_blocks) : BlockStorageDevice(cache_blocks) {
this->enable_cmd(ScsiCommand::READ_6);
this->enable_cmd(ScsiCommand::READ_10);
this->enable_cmd(ScsiCommand::READ_12);
this->enable_cmd(ScsiCommand::WRITE_6);
this->enable_cmd(ScsiCommand::WRITE_10);
this->enable_cmd(ScsiCommand::WRITE_12);
this->enable_cmd(ScsiCommand::START_STOP_UNIT);
this->enable_cmd(ScsiCommand::PREVENT_ALLOW_MEDIUM_REMOVAL);
this->enable_cmd(ScsiCommand::READ_CAPACITY);
this->add_page_getter(this, ModePage::ERROR_RECOVERY,
&ScsiBlockCmds::get_error_recovery_page);
}
void ScsiBlockCmds::init_block_device(uint8_t medium_type, uint8_t dev_flags) {
this->medium_type = medium_type;
this->device_flags = dev_flags;
phy_impl->set_read_more_data_cb(
[this](int* dsize, uint8_t** dptr) -> bool {
if (this->remain_size) {
*dsize = this->read_more();
*dptr = (uint8_t *)this->data_cache.get();
return true;
} else
return false;
}
);
if (this->is_writeable) {
phy_impl->set_write_more_data_cb(
[this](int* dsize, uint8_t** dptr) -> bool {
if (this->remain_size) {
*dsize = this->write_more();
*dptr = (uint8_t *)this->data_cache.get();
return true;
} else
return false;
}
);
} else {
phy_impl->set_write_more_data_cb(
[this](int* dsize, uint8_t** dptr) {
return false;
}
);
}
}
void ScsiBlockCmds::process_command() {
int next_phase;
// use non-disk buffer by default
phy_impl->set_buffer(this->buf_ptr);
switch(this->cdb_ptr[0]) {
case ScsiCommand::READ_6:
case ScsiCommand::READ_10:
case ScsiCommand::READ_12:
next_phase = this->read_new();
break;
case ScsiCommand::WRITE_6:
case ScsiCommand::WRITE_10:
case ScsiCommand::WRITE_12:
next_phase = this->write_new();
break;
case ScsiCommand::START_STOP_UNIT:
next_phase = this->start_stop_unit();
break;
case ScsiCommand::PREVENT_ALLOW_MEDIUM_REMOVAL:
phy_impl->set_eject_state((this->cdb_ptr[4] & 1) == 0);
next_phase = ScsiPhase::STATUS;
break;
case ScsiCommand::READ_CAPACITY:
next_phase = this->read_capacity();
break;
default:
ScsiCommonCmds::process_command();
return;
}
phy_impl->switch_phase(next_phase);
}
int ScsiBlockCmds::read_new() {
int nblocks = this->get_xfer_len();
// special case: zero transfer length means 256 blocks for READ_6
if (this->cdb_ptr[0] == ScsiCommand::READ_6) {
if (!nblocks)
nblocks = 256;
} else {
if ((this->cdb_ptr[1] & 1) && !this->linked_cmds_supported()) {
LOG_F(WARNING, "READ: RelAdr bit set");
this->set_field_pointer(1);
this->set_bit_pointer(0);
this->invalid_cdb();
return ScsiPhase::STATUS;
}
}
// go directly to the STATUS phase if nblocks = 0
if (!nblocks) {
LOG_F(WARNING, "READ: skip data transfer because nblocks = 0");
return ScsiPhase::STATUS;
}
this->set_fpos(this->get_lba());
phy_impl->set_xfer_len(this->read_begin(nblocks));
phy_impl->set_buffer((uint8_t *)this->data_cache.get());
return ScsiPhase::DATA_IN;
}
int ScsiBlockCmds::write_new() {
int nblocks = this->get_xfer_len();
// special case: zero transfer length means 256 blocks for WRITE_6
if (this->cdb_ptr[0] == ScsiCommand::WRITE_6) {
if (!nblocks)
nblocks = 256;
} else {
if ((this->cdb_ptr[1] & 1) && !this->linked_cmds_supported()) {
LOG_F(WARNING, "WRITE: RelAdr bit set");
this->set_field_pointer(1);
this->set_bit_pointer(0);
this->invalid_cdb();
return ScsiPhase::STATUS;
}
}
// go directly to the STATUS phase if nblocks = 0
if (!nblocks) {
LOG_F(WARNING, "WRITE: skip data transfer because nblocks = 0");
return ScsiPhase::STATUS;
}
this->set_fpos(this->get_lba());
phy_impl->set_xfer_len(this->write_begin(nblocks));
phy_impl->set_buffer((uint8_t *)this->data_cache.get());
phy_impl->set_post_xfer_action([this]() {
this->write_cache();
}
);
return ScsiPhase::DATA_OUT;
}
int ScsiBlockCmds::start_stop_unit() {
if (this->cdb_ptr[4] & 1) {
if (this->cdb_ptr[4] & 2)
LOG_F(INFO, "START_STOP_UNIT: medium load requested");
} else {
if (this->cdb_ptr[4] & 2) {
LOG_F(INFO, "START_STOP_UNIT: medium eject requested");
}
}
return ScsiPhase::STATUS;
}
int ScsiBlockCmds::read_capacity() {
uint32_t lba = this->get_lba();
if ((this->cdb_ptr[1] & 1) && !this->linked_cmds_supported()) {
LOG_F(WARNING, "READ_CAPACITY: RelAdr bit set");
this->set_field_pointer(1);
this->set_bit_pointer(0);
this->invalid_cdb();
return ScsiPhase::STATUS;
}
if (!(this->cdb_ptr[8] & 1) && lba) {
LOG_F(ERROR, "READ_CAPACITY: non-zero LBA for PMI=0");
this->set_field_pointer(2),
this->invalid_cdb();
return ScsiPhase::STATUS;
}
uint32_t last_lba = this->size_blocks - 1;
uint32_t blk_len = this->block_size;
WRITE_DWORD_BE_A(&this->buf_ptr[0], last_lba);
WRITE_DWORD_BE_A(&this->buf_ptr[4], blk_len);
phy_impl->set_xfer_len(8);
return ScsiPhase::DATA_IN;
}
int ScsiBlockCmds::format_block_descriptors(uint8_t* out_ptr) {
uint8_t density_code = 0;
uint32_t nblocks = std::min((int64_t)this->size_blocks, (int64_t)0xFFFFFFFFUL);
WRITE_DWORD_BE_A(&out_ptr[0], nblocks);
WRITE_DWORD_BE_A(&out_ptr[4], (density_code << 24) | (this->block_size & 0xFFFFFF));
return 8;
}
int ScsiBlockCmds::get_error_recovery_page(uint8_t ctrl, uint8_t subpage,
uint8_t *out_ptr, int avail_len)
{
if (subpage && subpage != 0xFFU)
return FORMAT_ERR_BAD_SUBPAGE;
if (ctrl == 3)
return FORMAT_ERR_BAD_CONTROL;
int page_size = 6;
if (page_size > avail_len)
return FORMAT_ERR_DATA_TOO_BIG;
std::memset(out_ptr, 0, page_size);
return page_size;
}
uint32_t ScsiBlockCmds::get_lba() {
int cmd_len = this->get_cdb_length(this->cdb_ptr[0]);
switch(cmd_len) {
case 6:
return ((this->cdb_ptr[1] & 0x1F) << 16) | READ_WORD_BE_A(&this->cdb_ptr[2]);
case 10:
case 12:
return READ_DWORD_BE_U(&this->cdb_ptr[2]);
default:
ABORT_F("unsupported command length %d in get_lba", cmd_len);
}
}
+63
View File
@@ -0,0 +1,63 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
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/>.
*/
#ifndef SCSI_BLOCK_COMMANDS_H
#define SCSI_BLOCK_COMMANDS_H
#include <devices/common/scsi/scsi.h>
#include <devices/common/scsi/scsicommoncmds.h>
#include <devices/storage/blockstoragedevice.h>
#include <cinttypes>
/** Base class for SCSI block device commands. */
class ScsiBlockCmds : public ScsiCommonCmds, public BlockStorageDevice {
public:
ScsiBlockCmds(int cache_blocks = 256);
~ScsiBlockCmds() = default;
void init_block_device(uint8_t medium_type, uint8_t dev_flags);
virtual int read_new();
virtual int write_new();
virtual int start_stop_unit();
virtual int read_capacity();
void get_medium_type(uint8_t& medium_type, uint8_t& dev_flags) override {
medium_type = this->medium_type;
dev_flags = this->device_flags;
}
int format_block_descriptors(uint8_t* out_ptr) override;
int get_error_recovery_page(uint8_t ctrl, uint8_t subpage, uint8_t *out_ptr,
int avail_len);
protected:
virtual void process_command() override;
uint32_t get_lba();
uint8_t medium_type = 0;
uint8_t device_flags = 0;
};
#endif // SCSI_BLOCK_COMMANDS_H
+4 -16
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -49,7 +49,7 @@ ScsiBus::ScsiBus(const std::string name)
this->target_id = -1;
}
void ScsiBus::register_device(int id, ScsiDevice* dev_obj)
void ScsiBus::register_device(int id, ScsiPhysDevice* dev_obj)
{
if (this->devices[id] != nullptr) {
ABORT_F("%s: device with ID %d already registered", this->get_name().c_str(), id);
@@ -298,18 +298,6 @@ void ScsiBus::target_next_step()
}
}
bool ScsiBus::negotiate_xfer(int& bytes_in, int& bytes_out)
{
if (target_id < 0) {
LOG_F(ERROR, "%s: target_id is not set yet.", this->get_name().c_str());
}
else {
this->devices[this->target_id]->prepare_xfer(this, bytes_in, bytes_out);
}
return true;
}
void ScsiBus::disconnect(int dev_id)
{
this->release_ctrl_lines(dev_id);
+3 -5
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -113,7 +113,6 @@ void ScsiBusController::sequencer() {
this->cur_state = SeqState::SEND_DATA;
break;
case ScsiPhase::DATA_IN:
this->bus_obj->negotiate_xfer(this->fifo_pos, this->bytes_out);
this->cur_state = SeqState::RCV_DATA;
this->rcv_data();
}
@@ -146,7 +145,6 @@ void ScsiBusController::sequencer() {
break;
case SeqState::RCV_STATUS:
case SeqState::RCV_MESSAGE:
this->bus_obj->negotiate_xfer(this->fifo_pos, this->bytes_out);
this->rcv_data();
if (this->is_initiator) {
if (this->cur_state == SeqState::RCV_STATUS) {
+6 -8
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -60,9 +60,9 @@ enum : int {
constexpr auto DATA_FIFO_DEPTH = 16;
class ScsiBusController : public ScsiDevice, public DmaDevice {
class ScsiBusController : public ScsiPhysDevice, public DmaDevice {
public:
ScsiBusController(std::string name, uint8_t my_bus_id=7) : ScsiDevice(name, my_bus_id) {
ScsiBusController(std::string name, uint8_t my_bus_id=7) : ScsiPhysDevice(name, my_bus_id) {
supports_types(HWCompType::SCSI_HOST | HWCompType::SCSI_DEV);
}
~ScsiBusController() = default;
@@ -73,10 +73,8 @@ public:
virtual void step_completed() = 0;
virtual void report_error(const int error) = 0;
// ScsiDevice methods
// ScsiPhysDevice methods
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) override;
+74 -138
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -32,56 +32,88 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
using namespace std;
ScsiCdrom::ScsiCdrom(std::string name, int my_id) : CdromDrive(), ScsiDevice(name, my_id)
static char my_vendor_id[] = "SONY ";
static char my_product_id[] = "CD-ROM CDU-8003A";
static char my_revision_id[] = "1.9a";
ScsiCdrom::ScsiCdrom(std::string name, int my_id) :
CdromDrive(), ScsiPhysDevice(name, my_id), ScsiCommonCmds()
{
this->set_phys_dev(this);
this->set_cdb_ptr(this->cmd_buf);
this->set_buf_ptr(this->data_buf);
this->set_error_callback(
[this](uint8_t sense_key, uint8_t asc) {
this->report_error(sense_key, asc);
//his->report_error(sense_key, asc);
this->invalid_cdb(); // HACK! to make CdromDrive::read_toc() work
}
);
this->set_read_more_data_cb(
[this](int* dsize, uint8_t** dptr) {
if (this->remain_size) {
*dsize = this->read_more();
*dptr = (uint8_t *)this->data_cache.get();
return true;
} else
return false;
}
);
this->set_write_more_data_cb(
[this](int* dsize, uint8_t** dptr) {
return false;
}
);
// populate device info for INQUIRY
this->dev_type = ScsiDevType::CD_ROM;
this->is_removable = true; // removable medium
this->std_versions = 2; // ISO vers=0, ECMA vers=0, ANSI vers=2 (SCSI-2)
this->resp_fmt = 2; // response data format: SCSI-2
this->cap_flags = CAP_SYNC_XFER; // supports synchronous transfers
this->set_vendor_id(my_vendor_id);
this->set_product_id(my_product_id);
this->set_revision_id(my_revision_id);
}
void ScsiCdrom::process_command()
{
uint32_t lba;
uint32_t cdda_start, cdda_end, cdda_len;
this->pre_xfer_action = nullptr;
this->post_xfer_action = nullptr;
if (this->verify_cdb() < 0) {
this->switch_phase(ScsiPhase::STATUS);
return;
}
// assume successful command execution
this->status = ScsiStatus::GOOD;
phy_impl->set_status(ScsiStatus::GOOD);
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
// use internal data buffer by default
this->data_ptr = this->data_buf;
phy_impl->set_buffer(this->data_buf);
uint8_t* cmd = this->cmd_buf;
switch (cmd[0]) {
case ScsiCommand::TEST_UNIT_READY:
this->test_unit_ready();
break;
case ScsiCommand::READ_6:
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
this->read(lba, cmd[4], 6);
break;
case ScsiCommand::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]);
break;
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);
break;
case ScsiCommand::READ_CAPACITY_10:
case ScsiCommand::READ_CAPACITY:
this->read_capacity_10();
break;
case ScsiCommand::READ_10:
@@ -94,127 +126,38 @@ void ScsiCdrom::process_command()
// CD-ROM specific commands
case ScsiCommand::READ_TOC:
this->bytes_out = read_toc(cmd, this->data_buf);
phy_impl->set_xfer_len(read_toc(cmd, this->data_buf));
if (this->status == ScsiStatus::GOOD) {
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
this->switch_phase(ScsiPhase::DATA_IN);
}
break;
case ScsiCommand::READ_CDDA:
lba = READ_DWORD_BE_U(&cmd[2]);
cdda_len = READ_DWORD_BE_U(&cmd[6]);
this->read(lba, cdda_len, 12);
break;
case ScsiCommand::READ_CDDA_MSF:
cdda_start = (cmd[3] * 60 * 75) + (cmd[4] * 75) + cmd[5];
cdda_end = (cmd[7] * 60 * 75) + (cmd[8] * 75) + cmd[9];
cdda_len = (cdda_end > cdda_start) ? (cdda_end - cdda_start) : 0;
this->read(cdda_start, cdda_len, 12);
break;
default:
LOG_F(ERROR, "%s: unsupported command 0x%X", this->name.c_str(), cmd[0]);
this->illegal_command(cmd);
ScsiCommonCmds::process_command();
}
}
bool ScsiCdrom::prepare_data()
{
switch (this->cur_phase) {
case ScsiPhase::DATA_IN:
this->data_size = this->bytes_out;
break;
case ScsiPhase::DATA_OUT:
this->data_size = 0;
break;
case ScsiPhase::STATUS:
break;
default:
LOG_F(WARNING, "%s: unexpected phase in prepare_data", this->name.c_str());
return false;
}
return true;
}
bool ScsiCdrom::get_more_data() {
if (this->data_left()) {
this->data_size = this->read_more();
this->data_ptr = (uint8_t *)this->data_cache.get();
}
return this->data_size != 0;
}
void ScsiCdrom::read(uint32_t lba, uint16_t nblocks, uint8_t cmd_len)
{
if (!check_lun())
return;
if (cmd_len == 6 && nblocks == 0)
nblocks = 256;
this->set_fpos(lba);
this->data_ptr = (uint8_t *)this->data_cache.get();
this->bytes_out = this->read_begin(nblocks, UINT32_MAX);
phy_impl->set_buffer((uint8_t *)this->data_cache.get());
phy_impl->set_xfer_len(this->read_begin(nblocks, UINT32_MAX));
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
this->switch_phase(ScsiPhase::DATA_IN);
}
int ScsiCdrom::test_unit_ready()
{
this->switch_phase(ScsiPhase::STATUS);
return ScsiError::NO_ERROR;
}
int ScsiCdrom::format_block_descriptors(uint8_t* out_ptr) {
uint8_t density_code = 1; // user data only, 2048 bytes per physical sector
uint32_t ScsiCdrom::inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr) {
int page_num = cmd_ptr[2];
int alloc_len = cmd_ptr[4];
WRITE_DWORD_BE_A(&out_ptr[0], (density_code << 24) | (this->size_blocks & 0xFFFFFF));
WRITE_DWORD_BE_A(&out_ptr[4], (this->block_size & 0xFFFFFF));
if (page_num) {
ABORT_F("%s: invalid page number in INQUIRY", this->name.c_str());
}
if (alloc_len > 36) {
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(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(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;
}
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, "%s: allocation length too small: %d", this->name.c_str(),
alloc_len);
}
else {
memset(&data_ptr[36], 0, alloc_len - 36);
}
return alloc_len;
return 8;
}
static char Apple_Copyright_Page_Data[] = "APPLE COMPUTER, INC ";
@@ -260,18 +203,17 @@ void ScsiCdrom::mode_sense_6()
this->data_buf[17] = 'p';
break;
default:
LOG_F(WARNING, "%s: unsupported page 0x%02x in MODE_SENSE_6", this->name.c_str(), page_code);
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;
LOG_F(WARNING, "%s: unsupported page 0x%02x in MODE_SENSE_6", this->name.c_str(),
page_code);
this->set_field_pointer(2), // error is in the 3rd byte
this->set_bit_pointer(5), // starting with bit 5
this->invalid_cdb();
this->switch_phase(ScsiPhase::STATUS);
return;
}
this->bytes_out = this->data_buf[0];
phy_impl->set_xfer_len(this->data_buf[0]);
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
this->switch_phase(ScsiPhase::DATA_IN);
@@ -282,7 +224,7 @@ void ScsiCdrom::mode_select_6(uint8_t param_len)
if (!param_len)
return;
this->incoming_size = param_len;
phy_impl->set_xfer_len(param_len);
std::memset(&this->data_buf[0], 0, 512);
@@ -304,25 +246,19 @@ void ScsiCdrom::read_capacity_10()
if (!(this->cmd_buf[8] & 1) && lba) {
LOG_F(ERROR, "%s: non-zero LBA for PMI=0", 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 = 8;
this->set_field_pointer(2),
this->invalid_cdb();
this->switch_phase(ScsiPhase::STATUS);
return;
}
if (!check_lun())
return;
int last_lba = (int)this->size_blocks - 1;
WRITE_DWORD_BE_A(&this->data_buf[0], last_lba);
WRITE_DWORD_BE_A(&this->data_buf[4], this->block_size);
this->bytes_out = 8;
phy_impl->set_xfer_len(8);
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
this->switch_phase(ScsiPhase::DATA_IN);
+16 -13
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -25,6 +25,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#define SCSI_CDROM_H
#include <devices/common/scsi/scsi.h>
#include <devices/common/scsi/scsicommoncmds.h>
#include <devices/storage/cdromdrive.h>
#include <utils/imgfile.h>
@@ -32,19 +33,26 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <memory>
#include <string>
class ScsiCdrom : public CdromDrive, public ScsiDevice {
class ScsiCdrom : public ScsiPhysDevice, public CdromDrive, public ScsiCommonCmds {
public:
ScsiCdrom(std::string name, int my_id);
~ScsiCdrom() = default;
virtual void process_command() override;
virtual bool prepare_data() override;
virtual bool get_more_data() override;
protected:
int test_unit_ready();
bool is_device_ready() override { return true; }
// temporary implementation that should be elsewhere
void get_medium_type(uint8_t& medium_type, uint8_t& dev_flags) override {
medium_type = 1; // 120mm CD-ROM data only
dev_flags = 0;
}
// temporary implementation that should be elsewhere
int format_block_descriptors(uint8_t* out_ptr) override;
void read(uint32_t lba, uint16_t nblocks, uint8_t cmd_len);
uint32_t inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr) override;
void mode_select_6(uint8_t param_len);
void mode_sense_6();
@@ -54,11 +62,6 @@ private:
bool eject_allowed = true;
int bytes_out = 0;
uint8_t data_buf[2048] = {};
//inquiry info
char vendor_info[9] = "SONY ";
char prod_info[17] = "CD-ROM CDU-8003A";
char rev_info[5] = "1.9a";
};
#endif // SCSI_CDROM_H
+447
View File
@@ -0,0 +1,447 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
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/>.
*/
#include <devices/common/scsi/scsicommoncmds.h>
#include <loguru.hpp>
#include <memaccess.h>
ScsiCommonCmds::ScsiCommonCmds() {
this->enable_cmd(ScsiCommand::TEST_UNIT_READY);
this->enable_cmd(ScsiCommand::REQ_SENSE);
this->enable_cmd(ScsiCommand::INQUIRY);
this->enable_cmd(ScsiCommand::MODE_SENSE_6);
this->enable_cmd(ScsiCommand::MODE_SENSE_10);
}
void ScsiCommonCmds::process_command() {
int next_phase;
switch(this->cdb_ptr[0]) {
case ScsiCommand::TEST_UNIT_READY:
next_phase = this->test_unit_ready();
break;
case ScsiCommand::REQ_SENSE:
next_phase = this->request_sense_new();
break;
case ScsiCommand::INQUIRY:
next_phase = this->inquiry_new();
break;
case ScsiCommand::MODE_SENSE_6:
case ScsiCommand::MODE_SENSE_10:
next_phase = this->mode_sense();
break;
default:
LOG_F(ERROR, "no support for command 0x%X", this->cdb_ptr[0]);
this->invalid_command();
next_phase = ScsiPhase::STATUS;
}
phy_impl->switch_phase(next_phase);
}
// maps command group number to CDB length (SCSI-2 standard §7.2.1)
static const int CmdGroupLen[8] = {6, 10, 10, CMD_GRP_RESERVED, CMD_GRP_RESERVED, 12,
CMD_GRP_VENDOR_SPECIFIC, CMD_GRP_VENDOR_SPECIFIC};
int ScsiCommonCmds::get_cdb_length(uint8_t op_code) {
return CmdGroupLen[op_code >> 5];
}
int ScsiCommonCmds::verify_cdb() {
if (phy_impl->get_phy_id() == PHY_ID_ATAPI)
return 0; // don't try to verify ATAPI packets
int cdb_len = this->get_cdb_length(this->cdb_ptr[0]);
if (cdb_len < 0)
return 0; // don't know how to verify non-standard CDBs
// check the LUN field except for INQUIRY and REQ_SENSE
if ((this->cdb_ptr[0] != ScsiCommand::INQUIRY) &&
(this->cdb_ptr[0] != ScsiCommand::REQ_SENSE))
{
if (phy_impl->last_sel_has_attention() &&
(phy_impl->last_sel_msg() & ScsiMessage::IDENTIFY))
{
uint8_t lun = phy_impl->last_sel_msg() & 7;
if (!this->lun_supported(lun)) {
LOG_F(ERROR, "unsupported LUN 0x%X", lun);
this->invalid_lun();
phy_impl->set_status(ScsiStatus::CHECK_CONDITION);
return -1;
}
} else if (this->cdb_ptr[1] >> 5)
LOG_F(WARNING, "non-zero LUN 0x%X in CDB", this->cdb_ptr[1] >> 5);
}
// check the control field
uint8_t ctrl_byte = this->cdb_ptr[cdb_len - 1];
if (ctrl_byte & 3) {
if (this->linked_cmds_supported())
this->link_ctrl = ctrl_byte;
else {
LOG_F(ERROR, "flag/link bit set in CDB control: 0x%X", ctrl_byte);
this->invalid_cdb();
return -1;
}
}
return 0;
}
int ScsiCommonCmds::test_unit_ready() {
// Assume that LUN is okay and the status has been set to GOOD
if (!phy_impl->is_device_ready()) {
this->sense_key = ScsiSense::NOT_READY;
this->asc = phy_impl->not_ready_reason();
this->ascq = 0;
phy_impl->set_status(ScsiStatus::CHECK_CONDITION);
}
return ScsiPhase::STATUS;
}
int ScsiCommonCmds::inquiry_new() {
int alloc_len = this->get_xfer_len();
int resp_len = 36; // standard response length
// go directly to the STATUS phase if alloc_len = 0
if (!alloc_len) {
LOG_F(WARNING, "INQUIRY: skip data transfer because alloc_len = 0");
return ScsiPhase::STATUS;
}
if (phy_impl->get_phy_id() == PHY_ID_SCSI) {
bool is_invalid = false;
if (this->cdb_ptr[1] & 1) {
LOG_F(ERROR, "INQUIRY: EVPD=1 not supported");
this->set_field_pointer(1);
this->set_bit_pointer(0);
is_invalid = true;
}
if (this->cdb_ptr[2]) {
LOG_F(ERROR, "INQUIRY: non-zero page code not supported");
this->set_field_pointer(2);
is_invalid = true;
}
if (is_invalid) {
this->invalid_cdb();
return ScsiPhase::STATUS;
}
}
std::memset(this->buf_ptr, 0, resp_len);
uint8_t lun = this->get_lun();
if (lun) {
// tell the host there is no device for this LUN
this->buf_ptr[0] = (3 << 5) | ScsiDevType::UNKNOWN;
LOG_F(WARNING, "INQUIRY: no device for LUN %d", lun);
} else {
this->buf_ptr[0] = this->dev_type;
this->buf_ptr[1] = ((this->is_removable) ? 0x80 : 0) | this->dev_type_mod;
this->buf_ptr[2] = this->std_versions;
this->buf_ptr[3] = this->resp_fmt;
this->buf_ptr[4] = 31; // additional length (n-5)
this->buf_ptr[7] = this->cap_flags;
std::memcpy(&this->buf_ptr[ 8], vendor_id, sizeof(this->vendor_id));
std::memcpy(&this->buf_ptr[16], product_id, sizeof(this->product_id));
std::memcpy(&this->buf_ptr[32], revision_id, sizeof(this->revision_id));
}
phy_impl->set_xfer_len(std::min(alloc_len, resp_len));
return ScsiPhase::DATA_IN;
}
int ScsiCommonCmds::request_sense_new() {
int alloc_len = this->get_xfer_len();
int resp_len = 18; // standard response length
// go directly to the STATUS phase if alloc_len = 0
if (!alloc_len) {
LOG_F(WARNING, "REQ_SENSE: skip data transfer because alloc_len = 0");
return ScsiPhase::STATUS;
}
std::memset(this->buf_ptr, 0, resp_len);
this->buf_ptr[0] = 0x80 | 0x70; // valid bit + current errors
this->buf_ptr[7] = 10; // additional sense length
uint8_t lun = this->get_lun();
if (lun) // unsupported LUN
this->invalid_lun();
this->buf_ptr[ 2] = this->sense_key;
this->buf_ptr[12] = this->asc;
this->buf_ptr[13] = this->ascq;
if (this->sense_key == ScsiSense::ILLEGAL_REQ && this->field_ptr_valid) {
this->buf_ptr[15] = this->is_cdb_err ? 0xC0 : 0x80;
WRITE_WORD_BE_A(&this->buf_ptr[16], this->field_ptr);
if (this->bit_ptr_valid)
this->buf_ptr[15] |= (this->bit_ptr & 7) | 8;
}
this->reset_sense(); // clear last sense information
phy_impl->set_xfer_len(std::min(alloc_len, resp_len));
return ScsiPhase::DATA_IN;
}
const char* Page_Control_Modes[4] = {
"CURRENT_VALUES",
"CHANGEABLE_VALUES",
"DEFAULT_VALUES",
"SAVED_VALUES"
};
int ScsiCommonCmds::mode_sense() {
uint8_t page_ctrl = this->cdb_ptr[2] >> 6;
if (page_ctrl == PageControl::SAVED_VALUES && !this->supports_params_saving()) {
LOG_F(ERROR, "MODE_SENSE: Page control mode (%s) not supported",
Page_Control_Modes[page_ctrl]);
this->set_field_pointer(2), // error in the 3rd byte
this->set_bit_pointer(7), // starting with bit 7
this->illegal_request(ScsiError::SAVING_NOT_SUPPORTED, 0);
return ScsiPhase::STATUS;
}
uint8_t page_code = this->cdb_ptr[2] & 0x3F;
uint8_t subpage_code = this->cdb_ptr[3];
// MODE_SENSE_10 returns a bigger response
bool is_long_resp = this->cdb_ptr[0] == ScsiCommand::MODE_SENSE_10;
int alloc_len = this->get_xfer_len();
int resp_len = 0;
int resp_max_len = is_long_resp ? 65536 : 256;
uint8_t* out_ptr = this->buf_ptr;
uint8_t medium_type, dev_flags;
this->get_medium_type(medium_type, dev_flags);
// format response header
if (is_long_resp) { // MODE_SENSE_10
WRITE_WORD_BE_A(out_ptr, 0); // zero data_length -> to be adjusted later
out_ptr[2] = medium_type;
out_ptr[3] = dev_flags;
resp_len = 8; // initial response length
out_ptr += 8; // move data pointer past block descriptor length
WRITE_WORD_BE_A(&out_ptr[-2], 0); // zero block descriptor length
} else {
out_ptr[0] = 0; // zero data_length -> to be adjusted later
out_ptr[1] = medium_type;
out_ptr[2] = dev_flags;
resp_len = 4; // initial response length
out_ptr += 4; // move data pointer past block descriptor length
out_ptr[-1] = 0; // zero block descriptor length
}
// return block descriptor(s) unless
// it's ATAPI that doesn't use block descriptors
// block descriptors are disabled by the DBD bit
if (phy_impl->get_phy_id() == PHY_ID_SCSI) {
if (!(this->cdb_ptr[1] & 8)) { // if DBD=0
int desc_len = this->format_block_descriptors(out_ptr);
if (is_long_resp)
WRITE_WORD_BE_A(&out_ptr[-2], desc_len);
else
out_ptr[-1] = desc_len;
out_ptr += desc_len;
resp_len += desc_len;
} else
LOG_F(WARNING, "MODE_SENSE: block descriptor(s) disabled");
}
// return all pages if requested
if (page_code == ModePage::ALL_PAGES) {
for (const auto& [page_num, formatter] : this->getters) {
if (!page_num)
continue; // skip vendor specific page 0 - shall be returned last
int page_len = this->get_one_page(page_ctrl, page_num, 0,
out_ptr, resp_max_len - resp_len);
if (page_len < 0)
return ScsiPhase::STATUS;
out_ptr += page_len;
resp_len += page_len;
}
if (this->getters.count(0))
page_code = 0; // page 0 exists -> let the following code return it last
}
// return one page
if (page_code != ModePage::ALL_PAGES) {
if (this->getters.count(page_code)) {
int page_len = this->get_one_page(page_ctrl, page_code, subpage_code,
out_ptr, resp_max_len - resp_len);
if (page_len < 0)
return ScsiPhase::STATUS;
resp_len += page_len;
} else {
LOG_F(ERROR, "MODE_SENSE: page 0x%X not supported", page_code);
this->set_field_pointer(2), // error in the 3rd byte
this->set_bit_pointer(5), // starting with bit 5
this->invalid_cdb();
return ScsiPhase::STATUS;
}
}
// stuff final response into response header
if (is_long_resp)
WRITE_WORD_BE_A(&this->buf_ptr[0], resp_len - 2);
else
this->buf_ptr[0] = resp_len - 1;
phy_impl->set_xfer_len(std::min(alloc_len, resp_len));
return ScsiPhase::DATA_IN;
}
int ScsiCommonCmds::get_one_page(uint8_t ctrl, uint8_t page, uint8_t subpage,
uint8_t* out_ptr, int avail_len)
{
int len, err;
try_again:
len = this->getters[page](ctrl, subpage, &out_ptr[2], avail_len - 2);
if (len < 0) {
err = len;
if (err == FORMAT_ERR_DATA_TOO_BIG) {
ABORT_F("Internal buffer too small!");
// increase buffer size
// goto try_again;
} else if (err == FORMAT_ERR_BAD_CONTROL) {
LOG_F(ERROR, "MODE_SENSE: Page control (%s) not supported for page 0x%X",
Page_Control_Modes[ctrl], page);
this->set_field_pointer(2), // error in the 3rd byte
this->set_bit_pointer(7); // starting with bit 7
} else if (err == FORMAT_ERR_BAD_SUBPAGE) {
LOG_F(ERROR, "MODE_SENSE: unsupported subpage 0x%X for page 0x%X",
subpage, page);
this->set_field_pointer(3); // error in the 4th byte
} else
ABORT_F("MODE_SENSE: unknown getter error %d", err);
this->invalid_cdb();
return err;
}
out_ptr[0] = page;
out_ptr[1] = len;
return len + 2;
}
uint8_t ScsiCommonCmds::get_lun() {
if (phy_impl->get_phy_id() == PHY_ID_ATAPI)
return 0; // ATAPI doesn't support SCSI LUNs so bail out early
if (phy_impl->last_sel_has_attention() &&
(phy_impl->last_sel_msg() & ScsiMessage::IDENTIFY))
return phy_impl->last_sel_msg() & 7;
else
return this->cdb_ptr[1] >> 5;
}
uint32_t ScsiCommonCmds::get_xfer_len() {
int cmd_len = this->get_cdb_length(this->cdb_ptr[0]);
switch(cmd_len) {
case 6:
return this->cdb_ptr[4];
case 10:
return READ_WORD_BE_U(&this->cdb_ptr[7]);
case 12:
return READ_DWORD_BE_U(&this->cdb_ptr[6]);
default:
ABORT_F("unsupported command length %d in get_xfer_len", cmd_len);
}
}
void ScsiCommonCmds::reset_sense() {
this->sense_key = ScsiSense::NO_SENSE;
this->asc = ScsiError::NO_ERROR;
this->ascq = 0;
this->field_ptr_valid = false;
this->bit_ptr_valid = false;
}
void ScsiCommonCmds::invalid_lun() {
this->sense_key = ScsiSense::ILLEGAL_REQ;
this->asc = ScsiError::INVALID_LUN;
this->ascq = 0;
this->is_cdb_err = true;
this->field_ptr_valid = true;
this->field_ptr = 1; // error in the 2nd byte
this->bit_ptr_valid = true;
this->bit_ptr = 7; // MSB number of the invalid bitfield
}
void ScsiCommonCmds::invalid_cdb() {
this->sense_key = ScsiSense::ILLEGAL_REQ;
this->asc = ScsiError::INVALID_CDB;
this->ascq = 0;
this->is_cdb_err = true;
phy_impl->set_status(ScsiStatus::CHECK_CONDITION);
}
void ScsiCommonCmds::invalid_command() {
LOG_F(ERROR, "unsupported command: 0x%02x", this->cdb_ptr[0]);
this->sense_key = ScsiSense::ILLEGAL_REQ;
this->asc = ScsiError::INVALID_CMD;
this->ascq = 0;
this->is_cdb_err = true;
this->field_ptr_valid = true;
this->field_ptr = 0; // error in the 1st byte
phy_impl->set_status(ScsiStatus::CHECK_CONDITION);
}
void ScsiCommonCmds::illegal_request(uint8_t asc, uint8_t ascq, bool is_cdb) {
this->sense_key = ScsiSense::ILLEGAL_REQ;
this->asc = asc;
this->ascq = ascq;
this->is_cdb_err = is_cdb;
phy_impl->set_status(ScsiStatus::CHECK_CONDITION);
}
+173
View File
@@ -0,0 +1,173 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
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/>.
*/
#ifndef SCSI_COMMON_COMMANDS_H
#define SCSI_COMMON_COMMANDS_H
#include <core/bitops.h>
#include <devices/common/scsi/scsi.h>
#include <devices/common/scsi/scsiphysinterface.h>
#include <array>
#include <cinttypes>
#include <cstring>
#include <functional>
#include <map>
/** IDs for command groups with non-standard length. */
enum : int {
CMD_GRP_RESERVED = -1,
CMD_GRP_VENDOR_SPECIFIC = -2,
};
/** Errors returned by mode sense page formatters. */
enum {
FORMAT_ERR_BAD_SUBPAGE = -1,
FORMAT_ERR_BAD_CONTROL = -2,
FORMAT_ERR_DATA_TOO_BIG = -3,
};
typedef std::function<int(uint8_t, uint8_t, uint8_t *, int)> page_getter_t;
/** Base class for common SCSI commands. */
class ScsiCommonCmds {
public:
ScsiCommonCmds();
~ScsiCommonCmds() = default;
void set_phys_dev(ScsiPhysInterface* dev_obj) { this->phy_impl = dev_obj; }
void set_cdb_ptr(uint8_t* ptr) { this->cdb_ptr = ptr; }
void set_buf_ptr(uint8_t* ptr) { this->buf_ptr = ptr; }
virtual int verify_cdb();
virtual int get_cdb_length(uint8_t op_code);
// override this to support several LUNs
virtual bool lun_supported(uint8_t lun) { return lun == 0; }
// override it in the sub-classes to support saving of device parameters
virtual bool supports_params_saving() { return false; }
// override this to support linked commands
virtual bool linked_cmds_supported() { return false; }
// implement it in the sub-classes because those parameters are device specific
virtual void get_medium_type(uint8_t& medium_type, uint8_t& dev_flags) = 0;
// implement it in the sub-classes
virtual int format_block_descriptors(uint8_t* out_ptr) = 0;
template <typename T>
void add_page_getter(T *inst, int page, int(T::*func)(uint8_t, uint8_t, uint8_t *, int)) {
page_getter_t f = [=] (uint8_t ctrl, uint8_t page, uint8_t *out_ptr, int avail_len) {
return (inst->*func)(ctrl, page, out_ptr, avail_len);
};
this->getters.emplace(std::make_pair(page, f));
}
protected:
virtual void process_command();
virtual int test_unit_ready();
virtual int inquiry_new();
virtual int request_sense_new();
virtual int mode_sense();
virtual uint8_t get_lun();
virtual uint32_t get_xfer_len();
virtual void reset_sense();
virtual void invalid_lun();
virtual void invalid_cdb();
virtual void invalid_command();
virtual void illegal_request(uint8_t asc, uint8_t ascq, bool is_cdb = true);
int get_one_page(uint8_t ctrl, uint8_t page, uint8_t subpage, uint8_t* out_ptr,
int avail_len);
virtual void set_field_pointer(const uint16_t fp) {
this->field_ptr = fp;
this->field_ptr_valid = true;
}
virtual void set_bit_pointer(const uint8_t bp) {
this->bit_ptr = bp;
this->bit_ptr_valid = true;
}
bool cmd_enabled(uint8_t cmd) {
return bit_set(this->cmd_enables[cmd >> 3], cmd & 7);
}
void enable_cmd(uint8_t cmd) {
set_bit(this->cmd_enables[cmd >> 3], cmd & 7);
}
void disable_cmd(uint8_t cmd) {
clear_bit(this->cmd_enables[cmd >> 3], cmd & 7);
}
void set_vendor_id(char* vid) {
std::memset(this->vendor_id, 0, sizeof(this->vendor_id));
std::strncpy(this->vendor_id, vid, sizeof(this->vendor_id));
}
void set_product_id(char* pid) {
std::memset(this->product_id, 0, sizeof(this->product_id));
std::strncpy(this->product_id, pid, sizeof(this->product_id));
}
void set_revision_id(char* rid) {
std::memset(this->revision_id, 0, sizeof(this->revision_id));
std::strncpy(this->revision_id, rid, sizeof(this->revision_id));
}
ScsiPhysInterface* phy_impl = nullptr;
uint8_t* cdb_ptr = nullptr;
uint8_t* buf_ptr = nullptr;
std::array<uint8_t, 32> cmd_enables{};
// REQUEST SENSE state
uint8_t sense_key = ScsiSense::NO_SENSE;
uint8_t asc = 0; // additional sense code
uint8_t ascq = 0; // additional sense code qualifier
bool field_ptr_valid = false; // field pointer valid
bool bit_ptr_valid = false; // bit pointer valid
bool is_cdb_err = false; // error in CDB?
uint8_t bit_ptr = 0; // field pointer value
uint16_t field_ptr = 0; // bit pointer value
// INQUIRY state
uint8_t dev_type = ScsiDevType::UNKNOWN;
bool is_removable = false;
uint8_t dev_type_mod = 0;
uint8_t std_versions = 0; // compliance with some standards
uint8_t resp_fmt = 0;
uint8_t cap_flags = 0; // capability flags
char vendor_id[8] = {};
char product_id[16] = {};
char revision_id[4] = {};
uint8_t link_ctrl = 0; // control field from CDB
mutable std::map<int, page_getter_t> getters;
};
#endif // SCSI_COMMON_COMMANDS_H
+107 -426
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -22,265 +22,91 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/** @file Generic SCSI Hard Disk emulation. */
#include <core/timermanager.h>
#include <devices/common/scsi/scsi.h>
#include <devices/common/scsi/scsihd.h>
#include <devices/deviceregistry.h>
#include <loguru.hpp>
#include <machines/machineproperties.h>
#include <memaccess.h>
#include <fstream>
#include <cstring>
using namespace std;
static char my_vendor_id[] = "QUANTUM ";
static char my_product_id[] = "Emulated Disk ";
static char my_revision_id[] = "di01";
ScsiHardDisk::ScsiHardDisk(std::string name, int my_id) : ScsiDevice(name, my_id) {
this->data_buf_size = 1 << 22;
this->data_buf_obj = std::unique_ptr<uint8_t[]>(new uint8_t[this->data_buf_size]);
this->data_buf = this->data_buf_obj.get();
ScsiHardDisk::ScsiHardDisk(std::string name, int my_id) : ScsiPhysDevice(name, my_id)
{
this->set_phys_dev(this);
this->set_cdb_ptr(this->cmd_buf);
this->set_buf_ptr(this->data_buf);
this->set_buffer(this->data_buf);
// populate device info for INQUIRY
this->dev_type = ScsiDevType::DIRECT_ACCESS; // direct access device (hard drive)
this->is_removable = false; // non-removable medium
this->std_versions = 2; // ISO vers=0, ECMA vers=0, ANSI vers=2 (SCSI-2)
this->resp_fmt = 2; // response data format: SCSI-2
this->cap_flags = CAP_SYNC_XFER; // indicate support for synchronous transfers
this->set_vendor_id(my_vendor_id);
this->set_product_id(my_product_id);
this->set_revision_id(my_revision_id);
this->add_page_getter(this, ModePage::DEV_FORMAT_PARAMS, &ScsiHardDisk::get_dev_format_page);
this->add_page_getter(this, ModePage::RIGID_DISK_GEOMETRY, &ScsiHardDisk::get_rigid_geometry_page);
this->add_page_getter(this, 0x30, &ScsiHardDisk::get_apple_copyright_page);
}
void ScsiHardDisk::insert_image(std::string filename) {
//We don't want to store everything in memory, but
//we want to keep the hard disk available.
if (!this->disk_img.open(filename))
if (this->set_host_file(filename) < 0)
ABORT_F("%s: could not open image file %s", this->name.c_str(), filename.c_str());
this->img_size = this->disk_img.size();
uint64_t tb = (this->img_size + this->sector_size - 1) / this->sector_size;
this->total_blocks = static_cast<int>(tb);
if (this->total_blocks < 0 || tb != this->total_blocks) {
ABORT_F("%s: file size is too large", this->name.c_str());
}
if (this->size_blocks > 0xFFFFFFU)
ABORT_F("%s: image file too large", this->name.c_str());
this->is_writeable = true;
this->init_block_device(0, 0);
}
void ScsiHardDisk::process_command() {
uint32_t lba;
this->pre_xfer_action = nullptr;
this->post_xfer_action = nullptr;
if (this->verify_cdb() < 0) {
this->switch_phase(ScsiPhase::STATUS);
return;
}
// use non-disk buffer by default
phy_impl->set_buffer(this->data_buf);
// assume successful command execution
this->status = ScsiStatus::GOOD;
phy_impl->set_status(ScsiStatus::GOOD);
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
uint8_t* cmd = this->cmd_buf;
switch (cmd[0]) {
case ScsiCommand::TEST_UNIT_READY:
this->test_unit_ready();
break;
case ScsiCommand::REQ_SENSE:
this->req_sense(cmd[4]);
break;
case ScsiCommand::FORMAT_UNIT:
this->format();
break;
case ScsiCommand::REASSIGN:
this->reassign();
break;
case ScsiCommand::READ_6:
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
this->read(lba, cmd[4], 6);
break;
case ScsiCommand::WRITE_6:
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
this->write(lba, cmd[4], 6);
break;
case ScsiCommand::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]);
break;
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);
break;
case ScsiCommand::READ_CAPACITY_10:
this->read_capacity_10();
break;
case ScsiCommand::READ_10:
lba = READ_DWORD_BE_U(&cmd[2]);
if (cmd[1] & 1) {
ABORT_F("%s: RelAdr bit set in READ_10", this->name.c_str());
}
this->read(lba, READ_WORD_BE_U(&cmd[7]), 10);
break;
case ScsiCommand::WRITE_10:
lba = READ_DWORD_BE_U(&cmd[2]);
this->write(lba, READ_WORD_BE_U(&cmd[7]), 10);
break;
case ScsiCommand::READ_BUFFER:
read_buffer();
break;
default:
this->illegal_command(cmd);
ScsiBlockCmds::process_command();
}
}
bool ScsiHardDisk::prepare_data() {
switch (this->cur_phase) {
case ScsiPhase::DATA_IN:
this->data_ptr = (uint8_t*)this->data_buf;
this->data_size = this->bytes_out;
break;
case ScsiPhase::DATA_OUT:
this->data_ptr = (uint8_t*)this->data_buf;
this->data_size = 0;
break;
case ScsiPhase::STATUS:
if (!error) {
this->data_buf[0] = ScsiStatus::GOOD;
} else {
this->data_buf[0] = ScsiStatus::CHECK_CONDITION;
}
this->bytes_out = 1;
this->data_ptr = (uint8_t*)this->data_buf;
this->data_size = this->bytes_out;
break;
case ScsiPhase::MESSAGE_IN:
this->data_buf[0] = this->msg_code;
this->bytes_out = 1;
this->data_ptr = (uint8_t*)this->data_buf;
this->data_size = this->bytes_out;
break;
default:
LOG_F(WARNING, "%s: unexpected phase in prepare_data", this->name.c_str());
return false;
}
return true;
}
int ScsiHardDisk::test_unit_ready() {
this->switch_phase(ScsiPhase::STATUS);
return ScsiError::NO_ERROR;
}
int ScsiHardDisk::req_sense(uint16_t alloc_len) {
//if (!check_lun())
// return;
//int next_phase;
int lun;
if (this->last_selection_has_atention) {
lun = this->last_selection_message & 7;
}
else {
lun = cmd_buf[1] >> 5;
}
if (lun == this->lun) {
this->status = ScsiStatus::GOOD;
this->data_buf[ 2] = this->sense; // Reserved:0xf0, Sense Key:0x0f ; e.g. ScsiSense::ILLEGAL_REQ
this->data_buf[12] = this->asc; // addition sense code
this->data_buf[13] = this->ascq; // additional sense qualifier
this->data_buf[15] = this->sksv; // SKSV:0x80, C/D:0x40, Reserved:0x30, BPV:8, Bit Pointer:7
this->data_buf[16] = this->field >> 8; // field pointer
this->data_buf[17] = this->field;
}
else {
this->data_buf[ 2] = this->sense; // Reserved:0xf0, Sense Key:0x0f ; e.g. ScsiSense::ILLEGAL_REQ
this->data_buf[12] = ScsiError::INVALID_LUN; // addition sense code = Logical Unit Not Supported
this->data_buf[13] = 0; // additional sense qualifier
this->data_buf[15] = 0; // SKSV:0x80, C/D:0x40, Reserved:0x30, BPV:8, Bit Pointer:7
this->data_buf[16] = 0; // field pointer
this->data_buf[17] = 0;
}
{
// FIXME: there should be a way to set the VALID and ILI bits.
this->data_buf[ 0] = 0x70; // Valid:0x80, Error Code:0x7f
this->data_buf[ 1] = 0; // segment number
this->data_buf[ 3] = 0; // information
this->data_buf[ 4] = 0;
this->data_buf[ 5] = 0;
this->data_buf[ 6] = 0;
this->data_buf[ 7] = 10; // additional sense length
this->data_buf[ 8] = 0; // command specific information
this->data_buf[ 9] = 0;
this->data_buf[10] = 0;
this->data_buf[11] = 0;
this->data_buf[14] = 0; // field replaceable unit code
this->data_buf[18] = 0; // reserved
this->data_buf[19] = 0; // reserved
}
this->bytes_out = alloc_len; // Open Firmware 1.0.5 asks for 18 bytes.
this->switch_phase(ScsiPhase::DATA_IN);
return ScsiError::NO_ERROR;
}
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(WARNING, "%s: more than 36 bytes requested in INQUIRY", this->name.c_str());
}
int lun;
if (this->last_selection_has_atention) {
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(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;
}
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) {
LOG_F(ERROR, "%s: allocation length too small: %d", this->name.c_str(),
alloc_len);
}
else {
memset(&data_ptr[36], 0, alloc_len - 36);
}
return alloc_len;
}
int ScsiHardDisk::send_diagnostic() {
return 0x0;
}
void ScsiHardDisk::mode_select_6(uint8_t param_len) {
if (!param_len) {
this->switch_phase(ScsiPhase::STATUS);
return;
}
this->incoming_size = param_len;
phy_impl->set_xfer_len(param_len);
std::memset(&this->data_buf[0], 0xDD, this->sector_size);
std::memset(&this->data_buf[0], 0xDD, this->block_size);
this->post_xfer_action = [this]() {
// TODO: parse the received mode parameter list here
@@ -289,164 +115,83 @@ void ScsiHardDisk::mode_select_6(uint8_t param_len) {
this->switch_phase(ScsiPhase::DATA_OUT);
}
static char Apple_Copyright_Page_Data[] = "APPLE COMPUTER, INC ";
int ScsiHardDisk::get_dev_format_page(uint8_t ctrl, uint8_t subpage, uint8_t *out_ptr,
int avail_len)
{
if (subpage && subpage != 0xFFU)
return FORMAT_ERR_BAD_SUBPAGE;
void ScsiHardDisk::mode_sense_6() {
uint8_t page_code = this->cmd_buf[2] & 0x3F;
uint8_t page_ctrl = this->cmd_buf[2] >> 6;
uint8_t sub_page_code = this->cmd_buf[3];
uint8_t alloc_len = this->cmd_buf[4];
if (ctrl == 3)
return FORMAT_ERR_BAD_CONTROL;
if (page_ctrl == 1) {
LOG_F(INFO, "%s: page_ctrl 1 CHANGEABLE 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;
}
int page_size = 22;
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;
this->sense = ScsiSense::ILLEGAL_REQ;
this->asc = SAVING_NOT_SUPPORTED;
this->ascq = 0;
this->sksv = 0;
this->field = 0;
this->switch_phase(ScsiPhase::STATUS);
return;
}
if (page_size > avail_len)
return FORMAT_ERR_DATA_TOO_BIG;
this->data_buf[ 1] = 0; // medium type
this->data_buf[ 2] = 0; // 0:medium is not write protected; 0x80 write protected
std::memset(out_ptr, 0, page_size);
this->data_buf[ 3] = 8; // block description length
WRITE_DWORD_BE_A(&this->data_buf[4], this->total_blocks);
WRITE_DWORD_BE_A(&this->data_buf[8], this->sector_size);
// default values taken from Empire 540/1080S manual
WRITE_WORD_BE_U(&out_ptr[ 0], 6); // tracks per defect zone
WRITE_WORD_BE_U(&out_ptr[ 2], 1); // alternate sectors per zone
WRITE_WORD_BE_U(&out_ptr[ 8], 64); // sectors per track in the outermost zone
WRITE_WORD_BE_U(&out_ptr[10], this->block_size); // bytes per sector
WRITE_WORD_BE_U(&out_ptr[12], 1); // interleave factor
WRITE_WORD_BE_U(&out_ptr[14], 19); // track skew factor
WRITE_WORD_BE_U(&out_ptr[16], 25); // cylinder skew factor
uint8_t *p_buf = &this->data_buf[12];
bool got_page = false;
int page_size;
out_ptr[18] = 0x80; // SSEC=1, HSEC=0, RMB=0, SURF=0, INS=0
if (page_code == 1 || page_code == 0x3f) { // read-write error recovery page
if (sub_page_code != 0x00 && sub_page_code != 0xff)
goto bad_sub_page;
page_size = 8;
p_buf[0] = 1; // page code
p_buf[1] = page_size - 2; // data size - 1
std::memset(&p_buf[2], 0, 6);
p_buf += page_size;
got_page = true;
}
if (page_code == 3 || page_code == 0x3f) { // Format device page
if (sub_page_code != 0x00 && sub_page_code != 0xff)
goto bad_sub_page;
page_size = 24;
p_buf[ 0] = 3; // page code
p_buf[ 1] = page_size - 2; // data size - 1
std::memset(&p_buf[2], 0, 22);
// default values taken from Empire 540/1080S manual
WRITE_WORD_BE_U(&p_buf[ 2], 6); // tracks per defect zone
WRITE_WORD_BE_U(&p_buf[ 4], 1); // alternate sectors per zone
WRITE_WORD_BE_U(&p_buf[10], 64); // sectors per track in the outermost zone
WRITE_WORD_BE_U(&p_buf[12], 512); // bytes per sector
WRITE_WORD_BE_U(&p_buf[14], 1); // interleave factor
WRITE_WORD_BE_U(&p_buf[16], 19); // track skew factor
WRITE_WORD_BE_U(&p_buf[18], 25); // cylinder skew factor
p_buf[20] = 0x80; // SSEC=1, HSEC=0, RMB=0, SURF=0, INS=0
p_buf += page_size;
got_page = true;
}
if (page_code == 4 || page_code == 0x3f) { // Rigid Disk Drive Geometry Page
page_size = 24;
p_buf[0] = 4; // page code
p_buf[1] = page_size - 2; // page length
std::memset(&p_buf[2], 0, 22);
int num_cylinders = this->total_blocks / 64 / 4;
p_buf[2] = (num_cylinders >> 16) & 0xFF;
WRITE_WORD_BE_U(&p_buf[3], num_cylinders & 0xFFFFU); // number of cylinders
p_buf[5] = 4; // number of heads
got_page = true;
}
if (page_code == 0x30 || page_code == 0x3f) { // Copyright page for Apple certified drives
if (sub_page_code != 0x00 && sub_page_code != 0xff)
goto bad_sub_page;
page_size = 24;
p_buf[0] = 0x30; // page code
p_buf[1] = page_size - 2; // data size - 1
std::memcpy(&p_buf[2], Apple_Copyright_Page_Data, 22);
p_buf += page_size;
got_page = true;
}
if (!(got_page || page_code == 0x3f)) { // not any of the supported pages or all pages
LOG_F(WARNING, "%s: unsupported page 0x%02x in MODE_SENSE_6", this->name.c_str(), page_code);
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;
bad_sub_page:
LOG_F(WARNING, "%s: unsupported page/subpage %02xh/%02xh in MODE_SENSE_6", this->name.c_str(), page_code, sub_page_code);
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 = 3;
this->switch_phase(ScsiPhase::STATUS);
return;
}
// adjust for overall mode sense data length
this->data_buf[0] = p_buf - this->data_buf - 1;
this->bytes_out = std::min((int)alloc_len, (int)this->data_buf[0] + 1);
this->switch_phase(ScsiPhase::DATA_IN);
return page_size;
}
void ScsiHardDisk::read_capacity_10() {
uint32_t lba = READ_DWORD_BE_U(&this->cmd_buf[2]);
int ScsiHardDisk::get_rigid_geometry_page(uint8_t ctrl, uint8_t subpage, uint8_t *out_ptr,
int avail_len)
{
if (subpage && subpage != 0xFFU)
return FORMAT_ERR_BAD_SUBPAGE;
if (this->cmd_buf[1] & 1) {
ABORT_F("%s: RelAdr bit set in READ_CAPACITY_10", this->name.c_str());
}
if (ctrl == 3)
return FORMAT_ERR_BAD_CONTROL;
if (!(this->cmd_buf[8] & 1) && lba) {
LOG_F(ERROR, "%s: non-zero LBA for PMI=0", 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 = 8;
this->switch_phase(ScsiPhase::STATUS);
return;
}
int page_size = 22;
if (!check_lun())
return;
if (page_size > avail_len)
return FORMAT_ERR_DATA_TOO_BIG;
uint32_t last_lba = this->total_blocks - 1;
uint32_t blk_len = this->sector_size;
std::memset(out_ptr, 0, page_size);
WRITE_DWORD_BE_A(&this->data_buf[0], last_lba);
WRITE_DWORD_BE_A(&this->data_buf[4], blk_len);
// num_cylinders = total_blocks / sectors_per_track / number_of_heads
int num_cylinders = this->size_blocks / 64 / 4;
this->bytes_out = 8;
// num_cylinders is a 24bit value!
out_ptr[0] = (num_cylinders >> 16) & 0xFF;
WRITE_WORD_BE_U(&out_ptr[1], num_cylinders & 0xFFFFU);
this->switch_phase(ScsiPhase::DATA_IN);
out_ptr[3] = 4; // number of heads
return page_size;
}
static char Apple_Copyright_Page_Data[] = "APPLE COMPUTER, INC ";
int ScsiHardDisk::get_apple_copyright_page(uint8_t ctrl, uint8_t subpage, uint8_t *out_ptr,
int avail_len)
{
if (subpage && subpage != 0xFFU)
return FORMAT_ERR_BAD_SUBPAGE;
if (ctrl == 3)
return FORMAT_ERR_BAD_CONTROL;
int page_size = 22;
if (page_size > avail_len)
return FORMAT_ERR_DATA_TOO_BIG;
std::memcpy(out_ptr, Apple_Copyright_Page_Data, page_size);
return page_size;
}
void ScsiHardDisk::format() {
@@ -460,70 +205,6 @@ void ScsiHardDisk::format() {
});
}
void ScsiHardDisk::reassign() {
LOG_F(WARNING, "%s: attempt to reassign blocks on the disk!", this->name.c_str());
this->status = ScsiStatus::GOOD;
this->sense = ScsiSense::NO_SENSE;
this->asc = ScsiError::NO_ERROR;
this->valid = false;
TimerManager::get_instance()->add_oneshot_timer(
NS_PER_SEC, [this]() { this->switch_phase(ScsiPhase::STATUS); });
}
void ScsiHardDisk::read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
if (!check_lun())
return;
uint32_t transfer_size = transfer_len;
if (cmd_len == 6 && transfer_len == 0) {
transfer_size = 256;
}
transfer_size *= this->sector_size;
if (transfer_size > this->data_buf_size) {
while (transfer_size > this->data_buf_size)
this->data_buf_size <<= 1;
this->data_buf_obj = std::unique_ptr<uint8_t[]>(new uint8_t[this->data_buf_size]);
this->data_buf = this->data_buf_obj.get();
}
std::memset(this->data_buf, 0, transfer_size);
uint64_t device_offset = (uint64_t)lba * this->sector_size;
this->disk_img.read(this->data_buf, device_offset, transfer_size);
this->bytes_out = transfer_size;
this->switch_phase(ScsiPhase::DATA_IN);
}
void ScsiHardDisk::write(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
uint32_t transfer_size = transfer_len;
if (cmd_len == 6 && transfer_len == 0) {
transfer_size = 256;
}
transfer_size *= this->sector_size;
if (transfer_size > this->data_buf_size) {
while (transfer_size > this->data_buf_size)
this->data_buf_size <<= 1;
this->data_buf_obj = std::unique_ptr<uint8_t[]>(new uint8_t[this->data_buf_size]);
this->data_buf = this->data_buf_obj.get();
}
uint64_t device_offset = (uint64_t)lba * this->sector_size;
this->incoming_size = transfer_size;
this->post_xfer_action = [this, device_offset]() {
this->disk_img.write(this->data_buf, device_offset, this->incoming_size);
};
this->switch_phase(ScsiPhase::DATA_OUT);
}
void ScsiHardDisk::read_buffer() {
uint8_t mode = this->cmd_buf[1];
uint32_t alloc_len = (this->cmd_buf[6] << 24) | (this->cmd_buf[7] << 16) |
@@ -537,7 +218,7 @@ void ScsiHardDisk::read_buffer() {
ABORT_F("%s: unsupported mode %d in READ_BUFFER", this->name.c_str(), mode);
}
this->bytes_out = alloc_len;
phy_impl->set_xfer_len(alloc_len);
this->switch_phase(ScsiPhase::DATA_IN);
}
Loaded 100 of 206 files, more files were not shown because too many files have changed in this diff. Show more